Skip to content

Commit 3aad138

Browse files
committed
Cleanup error logs
1 parent da079ad commit 3aad138

20 files changed

+98
-58
lines changed

src/commands/analytics/cmd-analytics.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ async function run(
8484
const badRepo = scope === 'repo' && !repo
8585

8686
if (badScope || badTime || badRepo) {
87+
// Use exit status of 2 to indicate incorrect usage, generally invalid
88+
// options or missing arguments.
89+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
90+
process.exitCode = 2
8791
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
8892
- Scope must be "repo" or "org" ${badScope ? colors.red('(bad!)') : colors.green('(ok)')}\n
8993
- The time filter must either be 7, 30 or 90 ${badTime ? colors.red('(bad!)') : colors.green('(ok)')}\n
90-
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n
91-
`)
92-
process.exitCode = 2 // bad input
94+
- Repository name using --repo when scope is "repo" ${badRepo ? colors.red('(bad!)') : colors.green('(ok)')}\n`)
9395
return
9496
}
9597

src/commands/audit-log/cmd-audit-log.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ async function run(
6969
const [orgSlug = ''] = cli.input
7070

7171
if (!orgSlug) {
72+
// Use exit status of 2 to indicate incorrect usage, generally invalid
73+
// options or missing arguments.
74+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
75+
process.exitCode = 2
7276
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
73-
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
74-
`)
75-
process.exitCode = 2 // bad input
77+
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`)
7678
return
7779
}
7880

src/commands/cdxgen/cmd-cdxgen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,13 @@ async function run(
156156
const unknown: Array<string> = yargv._
157157
const { length: unknownLength } = unknown
158158
if (unknownLength) {
159+
// Use exit status of 2 to indicate incorrect usage, generally invalid
160+
// options or missing arguments.
161+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
162+
process.exitCode = 2
159163
console.error(
160164
`Unknown ${pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`
161165
)
162-
process.exitCode = 2 // bad input
163166
return
164167
}
165168

src/commands/diff-scan/cmd-diff-scan-get.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ async function run(
7676
const [orgSlug = ''] = cli.input
7777

7878
if (!before || !after || cli.input.length < 1) {
79+
// Use exit status of 2 to indicate incorrect usage, generally invalid
80+
// options or missing arguments.
81+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
82+
process.exitCode = 2
7983
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
8084
- Specify a before and after full scan ID ${!before && !after ? colors.red('(missing before and after!)') : !before ? colors.red('(missing before!)') : !after ? colors.red('(missing after!)') : colors.green('(ok)')}\n
8185
- To get full scans IDs, you can run the command "socket scan list <your org slug>".
82-
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n}
83-
`)
84-
process.exitCode = 2 // bad input
86+
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n`)
8587
return
8688
}
8789

src/commands/info/cmd-info.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ async function run(
5050
const [rawPkgName = ''] = cli.input
5151

5252
if (!rawPkgName || cli.input.length > 1) {
53+
// Use exit status of 2 to indicate incorrect usage, generally invalid
54+
// options or missing arguments.
55+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
56+
process.exitCode = 2
5357
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5458
- Expecting a package name ${!rawPkgName ? colors.red('(missing!)') : colors.green('(ok)')}\n
55-
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n
56-
`)
57-
process.exitCode = 2 // bad input
59+
- Can only accept one package at a time ${cli.input.length > 1 ? colors.red('(got ' + cli.input.length + '!)') : colors.green('(ok)')}\n`)
5860
return
5961
}
6062

src/commands/manifest/cmd-manifest-gradle.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ async function run(
117117
// TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
118118

119119
if (!target || target === '-' || cli.input.length > 1) {
120+
// Use exit status of 2 to indicate incorrect usage, generally invalid
121+
// options or missing arguments.
122+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
123+
process.exitCode = 2
120124
console.error(
121125
`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
122126
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
123-
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n
124-
`
127+
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`
125128
)
126-
process.exitCode = 2 // bad input
127129
return
128130
}
129131

src/commands/manifest/cmd-manifest-kotlin.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ async function run(
122122
// TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
123123

124124
if (!target || target === '-' || cli.input.length > 1) {
125+
// Use exit status of 2 to indicate incorrect usage, generally invalid
126+
// options or missing arguments.
127+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
128+
process.exitCode = 2
125129
console.error(
126130
`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
127131
- The DIR arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
128-
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n
129-
`
132+
- Can only accept one DIR (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`
130133
)
131-
process.exitCode = 2 // bad input
132134
return
133135
}
134136

src/commands/manifest/cmd-manifest-scala.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ async function run(
113113
// TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
114114

115115
if (!target || target === '-' || cli.input.length > 1) {
116+
// Use exit status of 2 to indicate incorrect usage, generally invalid
117+
// options or missing arguments.
118+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
119+
process.exitCode = 2
116120
console.error(
117121
`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
118122
- The DIR or FILE arg is required ${!target ? colors.red('(missing!)') : target === '-' ? colors.red('(stdin is not supported)') : colors.green('(ok)')}\n
119-
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n
120-
`
123+
- Can only accept one DIR or FILE (make sure to escape spaces!) ${cli.input.length > 1 ? colors.red(`(received ${cli.input.length}!)`) : colors.green('(ok)')}\n`
121124
)
122-
process.exitCode = 2 // bad input
123125
return
124126
}
125127

src/commands/report/cmd-report-view.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ async function run(
5050

5151
// Validate the input.
5252
if (extraInput.length || !reportId) {
53+
// Use exit status of 2 to indicate incorrect usage, generally invalid
54+
// options or missing arguments.
55+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
56+
process.exitCode = 2
5357
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
5458
- Need at least one report ID ${!reportId ? colors.red('(missing!)') : colors.green('(ok)')}\n
55-
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n
56-
`)
57-
process.exitCode = 2 // bad input
59+
- Can only handle a single report ID ${extraInput.length < 2 ? colors.red(`(received ${extraInput.length}!)`) : colors.green('(ok)')}\n`)
5860
return
5961
}
6062

src/commands/repos/cmd-repos-create.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ async function run(
8181
const [orgSlug = ''] = cli.input
8282

8383
if (!repoName || typeof repoName !== 'string' || !orgSlug) {
84+
// Use exit status of 2 to indicate incorrect usage, generally invalid
85+
// options or missing arguments.
86+
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
87+
process.exitCode = 2
8488
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
8589
- Org name as the first argument ${!orgSlug ? colors.red('(missing!)') : colors.green('(ok)')}\n
86-
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n
87-
`)
88-
process.exitCode = 2 // bad input
90+
- Repository name using --repoName ${!repoName ? colors.red('(missing!)') : typeof repoName !== 'string' ? colors.red('(invalid!)') : colors.green('(ok)')}\n`)
8991
return
9092
}
9193

0 commit comments

Comments
 (0)