From f8dbcd7c5fdbb5df9ef15ec5eb0d1d09c965b558 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Fri, 2 Feb 2024 18:41:07 -0500 Subject: [PATCH] Add detail to error messages. --- Scoop.js | 5 +++-- bin/cli.js | 9 +++++---- exporters/scoopToWACZ.js | 11 ++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Scoop.js b/Scoop.js index 2005a267..5a0a0329 100644 --- a/Scoop.js +++ b/Scoop.js @@ -22,6 +22,7 @@ import * as intercepters from './intercepters/index.js' import * as exporters from './exporters/index.js' import * as importers from './importers/index.js' import { filterOptions, defaults } from './options.js' +import { formatErrorMessage } from './utils/formatErrorMessage.js' nunjucks.configure(CONSTANTS.TEMPLATES_PATH) @@ -441,7 +442,7 @@ export class Scoop { this.log.info(`🍨 Starting capture of ${this.url}.`) this.state = Scoop.states.CAPTURE } catch (err) { - this.log.error('An error occurred during capture setup.') + this.log.error(`An error occurred during capture setup (${formatErrorMessage(err)}).`) this.log.trace(err) this.state = Scoop.states.FAILED return // exit early if the browser and proxy couldn't be launched @@ -569,7 +570,7 @@ export class Scoop { await access(CONSTANTS.TMP_PATH, fsConstants.W_OK) tmpDirExists = true } catch (err) { - this.log.warn(`Error while creating base temporary folder ${CONSTANTS.TMP_PATH}.`) + this.log.warn(`Error while creating base temporary folder ${CONSTANTS.TMP_PATH} ((${formatErrorMessage(err)})).`) this.log.trace(err) } } diff --git a/bin/cli.js b/bin/cli.js index 927c9b60..a7a5b493 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -8,6 +8,7 @@ import { Command, Option } from 'commander' import { Scoop } from '../Scoop.js' import { PACKAGE_INFO } from '../constants.js' +import { formatErrorMessage } from '../utils/formatErrorMessage.js' /** @type {Command} */ const program = new Command() @@ -455,7 +456,7 @@ program.action(async (name, options, command) => { } } catch (err) { capture.log.trace(err) - capture.log.error(`Something went wrong while preparing ${options.output}. Use --log-level trace for details.`) + capture.log.error(`Something went wrong while preparing ${options.output} (${formatErrorMessage(err)}). Use --log-level trace for details.`) process.exit(1) } @@ -467,7 +468,7 @@ program.action(async (name, options, command) => { capture.log.info(`${options.output} saved to disk.`) } catch (err) { capture.log.trace(err) - capture.log.error(`Something went wrong while saving ${options.output} to disk. Use --log-level trace for details.`) + capture.log.error(`Something went wrong while saving ${options.output} to disk (${formatErrorMessage(err)}). Use --log-level trace for details.`) process.exit(1) } @@ -483,7 +484,7 @@ program.action(async (name, options, command) => { capture.log.info(`${jsonSummaryOutput} saved to disk.`) } catch (err) { capture.log.trace(err) - capture.log.error(`Something went wrong while saving ${jsonSummaryOutput} to disk. Use --log-level trace for details.`) + capture.log.error(`Something went wrong while saving ${jsonSummaryOutput} to disk (${formatErrorMessage(err)}). Use --log-level trace for details.`) process.exit(1) } } @@ -504,7 +505,7 @@ program.action(async (name, options, command) => { } } catch (err) { capture.log.trace(err) - capture.log.error(`Something went wrong while exporting attachments to ${exportAttachmentsOutput}. Use --log-level trace for details.`) + capture.log.error(`Something went wrong while exporting attachments to ${exportAttachmentsOutput} (${formatErrorMessage(err)}). Use --log-level trace for details.`) process.exit(1) } } diff --git a/exporters/scoopToWACZ.js b/exporters/scoopToWACZ.js index c85d03f0..46353cda 100644 --- a/exporters/scoopToWACZ.js +++ b/exporters/scoopToWACZ.js @@ -8,6 +8,7 @@ import { WARCParser } from 'warcio' import { Scoop } from '../Scoop.js' import * as CONSTANTS from '../constants.js' import { getHead } from '../utils/http.js' +import { formatErrorMessage } from '../utils/formatErrorMessage.js' import { ScoopGeneratedExchange } from '../exchanges/ScoopGeneratedExchange.js' import { ScoopExchange } from '../exchanges/ScoopExchange.js' // eslint-disable-line @@ -86,7 +87,7 @@ export async function scoopToWACZ (capture, includeRaw = false, signingServer) { } catch (err) { capture.log.trace(err) await clearOutputDir() - throw new Error('An error occurred while creating underlying WARC file.') + throw new Error(`An error occurred while creating underlying WARC file (${formatErrorMessage(err)}).`) } // @@ -119,7 +120,7 @@ export async function scoopToWACZ (capture, includeRaw = false, signingServer) { } catch (err) { capture.log.trace(err) await clearOutputDir() - throw new Error('An error occurred while initializing WACZ output.') + throw new Error(`An error occurred while initializing WACZ output (${formatErrorMessage(err)}).`) } // @@ -150,7 +151,7 @@ export async function scoopToWACZ (capture, includeRaw = false, signingServer) { } catch (err) { capture.log.trace(err) await clearOutputDir() - throw new Error('An error occurred while adding pages to WACZ output.') + throw new Error(`An error occurred while adding pages to WACZ output (${formatErrorMessage(err)}).`) } // @@ -192,7 +193,7 @@ export async function scoopToWACZ (capture, includeRaw = false, signingServer) { } catch (err) { capture.log.trace(err) await clearOutputDir() - throw new Error('An error occurred while adding raw exchanges to WACZ output.') + throw new Error(`An error occurred while adding raw exchanges to WACZ output (${formatErrorMessage(err)}).`) } } @@ -205,7 +206,7 @@ export async function scoopToWACZ (capture, includeRaw = false, signingServer) { } catch (err) { capture.log.trace(err) await clearOutputDir() - throw new Error('An error occurred while processing WACZ file.') + throw new Error(`An error occurred while processing WACZ file (${formatErrorMessage(err)}).`) } await clearOutputDir()