Skip to content

Commit

Permalink
Add detail to error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccacremona committed Feb 2, 2024
1 parent 61ba529 commit f8dbcd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Scoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
9 changes: 5 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down
11 changes: 6 additions & 5 deletions exporters/scoopToWACZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)}).`)
}

//
Expand Down Expand Up @@ -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)}).`)
}

//
Expand Down Expand Up @@ -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)}).`)
}

//
Expand Down Expand Up @@ -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)}).`)
}
}

Expand All @@ -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()
Expand Down

0 comments on commit f8dbcd7

Please sign in to comment.