Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Restrict try-catch in upload command so build can be finalized #387

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions src/services/image-snapshot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,22 @@ export default class ImageSnapshotService extends PercyClientService {
}

async snapshotAll() {
try {
// intentially remove '' values from because that matches every file
const globs = this.configuration.files.split(',').filter(Boolean)
const ignore = this.configuration.ignore.split(',').filter(Boolean)
const paths = await globby(globs, { cwd: this.configuration.path, ignore })

if (!paths.length) {
logger.error(`no matching files found in '${this.configuration.path}''`)
logger.info('exiting')
return process.exit(1)
}
// intentially remove '' values from because that matches every file
const globs = this.configuration.files.split(',').filter(Boolean)
const ignore = this.configuration.ignore.split(',').filter(Boolean)
const paths = await globby(globs, { cwd: this.configuration.path, ignore })
let error

if (!paths.length) {
logger.error(`no matching files found in '${this.configuration.path}''`)
logger.info('exiting')
return process.exit(1)
}

await this.buildService.create()
logger.debug('uploading snapshots of static images')
await this.buildService.create()
logger.debug('uploading snapshots of static images')

try {
// wait for snapshots in parallel
await Promise.all(paths.reduce((promises, pathname) => {
logger.debug(`handling snapshot: '${pathname}'`)
Expand All @@ -140,12 +141,15 @@ export default class ImageSnapshotService extends PercyClientService {

return promises
}, [] as any[]))

// finalize build
await this.buildService.finalize()
} catch (error) {
logError(error)
process.exit(1)
} catch (err) {
error = err
logError(err)
}

// finalize build
await this.buildService.finalize()

// if an error occurred, exit with non-zero
if (error) process.exit(1)
}
}