Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Feb 26, 2024
1 parent f7844fb commit 3ed92c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ async function run() {
await executeAction(input, decideQueryStrategy(input), decideDeleteStrategy(input))
}

run().catch((error: string | Error) => setFailed(error))
function formatError(error: Error): string {
const cause = error.cause instanceof Error ? "\nCaused by: " + formatError(error.cause) : ""

return error.toString() + cause
}

run().catch((error: string | Error) => setFailed(error instanceof Error ? formatError(error) : error))
2 changes: 1 addition & 1 deletion src/query/strategies/organization.query.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class OrganizationQueryStrategy implements QueryStrategy {

return await this.octokit.rest.packages.getAllPackageVersionsForPackageOwnedByOrg(params)
} catch (error) {
throw new Error(`Failed to query package ${name}`, { cause: error })
throw new Error(`Failed to query package ${name} of type ${input.type}`, { cause: error })
}
}
}
2 changes: 1 addition & 1 deletion src/query/strategies/user.query.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class UserQueryStrategy implements QueryStrategy {

return await this.octokit.rest.packages.getAllPackageVersionsForPackageOwnedByUser(params)
} catch (error) {
throw new Error(`Failed to query package ${name}`, { cause: error })
throw new Error(`Failed to query package ${name} of type ${input.type}`, { cause: error })
}
}
}

0 comments on commit 3ed92c8

Please sign in to comment.