Skip to content

Commit cee7785

Browse files
committed
Make badge consistent, poish other error handling cases
1 parent 4954b94 commit cee7785

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+114
-195
lines changed

src/cli.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { pathToFileURL } from 'node:url'
55

66
import { messageWithCauses, stackWithCauses } from 'pony-cause'
77
import updateNotifier from 'tiny-updater'
8-
import colors from 'yoctocolors-cjs'
98

109
import { logger } from '@socketsecurity/registry/lib/logger'
1110

@@ -35,6 +34,7 @@ import { cmdThreatFeed } from './commands/threat-feed/cmd-threat-feed'
3534
import { cmdWrapper } from './commands/wrapper/cmd-wrapper'
3635
import constants from './constants'
3736
import { AuthError, InputError, captureException } from './utils/errors'
37+
import { failMsgWithBadge } from './utils/fail-msg-with-badge'
3838
import { meowWithSubcommands } from './utils/meow-with-subcommands'
3939

4040
const { SOCKET_CLI_BIN_NAME } = constants
@@ -107,9 +107,7 @@ void (async () => {
107107
} else {
108108
errorTitle = 'Unexpected error with no details'
109109
}
110-
logger.fail(
111-
`${colors.bgRed(colors.white(`${errorTitle}:`))} ${errorMessage}`
112-
)
110+
logger.fail(failMsgWithBadge(errorTitle, errorMessage))
113111
if (errorBody) {
114112
logger.error(`\n${errorBody}`)
115113
}

src/commands/analytics/cmd-analytics.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('socket analytics', async () => {
7070
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
7171
|_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: <redacted>
7272
73-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m:
73+
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
7474
7575
- Scope must be "repo" or "org" (\\x1b[32mok\\x1b[39m)
7676

src/commands/analytics/display-analytics.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { logger } from '@socketsecurity/registry/lib/logger'
1010
import { fetchOrgAnalyticsData } from './fetch-org-analytics'
1111
import { fetchRepoAnalyticsData } from './fetch-repo-analytics'
1212
import constants from '../../constants'
13-
import { AuthError } from '../../utils/errors'
1413
import { mdTableStringNumber } from '../../utils/markdown'
15-
import { getDefaultToken } from '../../utils/sdk'
1614

1715
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
1816
import type { Widgets } from 'blessed' // Note: Widgets does not seem to actually work as code :'(
@@ -76,38 +74,6 @@ export async function displayAnalytics({
7674
repo: string
7775
outputKind: 'json' | 'markdown' | 'print'
7876
filePath: string
79-
}): Promise<void> {
80-
const apiToken = getDefaultToken()
81-
if (!apiToken) {
82-
throw new AuthError(
83-
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API token.'
84-
)
85-
}
86-
87-
await outputAnalyticsWithToken({
88-
apiToken,
89-
filePath,
90-
outputKind,
91-
repo,
92-
scope,
93-
time
94-
})
95-
}
96-
97-
async function outputAnalyticsWithToken({
98-
apiToken,
99-
filePath,
100-
outputKind,
101-
repo,
102-
scope,
103-
time
104-
}: {
105-
apiToken: string
106-
scope: string
107-
time: number
108-
repo: string
109-
outputKind: 'json' | 'markdown' | 'print'
110-
filePath: string
11177
}): Promise<void> {
11278
// Lazily access constants.spinner.
11379
const { spinner } = constants
@@ -119,9 +85,9 @@ async function outputAnalyticsWithToken({
11985
| SocketSdkReturnType<'getOrgAnalytics'>['data']
12086
| SocketSdkReturnType<'getRepoAnalytics'>['data']
12187
if (scope === 'org') {
122-
data = await fetchOrgAnalyticsData(time, spinner, apiToken)
88+
data = await fetchOrgAnalyticsData(time, spinner)
12389
} else if (repo) {
124-
data = await fetchRepoAnalyticsData(repo, time, spinner, apiToken)
90+
data = await fetchRepoAnalyticsData(repo, time, spinner)
12591
}
12692

12793
// A message should already have been printed if we have no data here

src/commands/analytics/fetch-org-analytics.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import type { SocketSdkReturnType } from '@socketsecurity/sdk'
88

99
export async function fetchOrgAnalyticsData(
1010
time: number,
11-
spinner: Spinner,
12-
apiToken: string
11+
spinner: Spinner
1312
): Promise<SocketSdkReturnType<'getOrgAnalytics'>['data'] | undefined> {
14-
const sockSdk = await setupSdk(apiToken)
13+
const sockSdk = await setupSdk()
1514
const result = await handleApiCall(
1615
sockSdk.getOrgAnalytics(time.toString()),
1716
'fetching analytics data'

src/commands/analytics/fetch-repo-analytics.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import type { SocketSdkReturnType } from '@socketsecurity/sdk'
99
export async function fetchRepoAnalyticsData(
1010
repo: string,
1111
time: number,
12-
spinner: Spinner,
13-
apiToken: string
12+
spinner: Spinner
1413
): Promise<SocketSdkReturnType<'getRepoAnalytics'>['data'] | undefined> {
15-
const sockSdk = await setupSdk(apiToken)
14+
const sockSdk = await setupSdk()
1615
const result = await handleApiCall(
1716
sockSdk.getRepoAnalytics(repo, time.toString()),
1817
'fetching analytics data'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('socket audit-log', async () => {
6767
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
6868
|_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: <redacted>
6969
70-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m:
70+
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
7171
7272
- Org name should be the first arg (\\x1b[31mmissing\\x1b[39m)
7373

src/commands/cdxgen/cmd-cdxgen.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,6 @@ async function run(
147147
importMeta,
148148
parentName
149149
})
150-
// if (cli.input.length)
151-
// logger.fail(
152-
// stripIndents`
153-
// ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:
154-
//
155-
// - Unexpected arguments
156-
// `)
157-
// config.help(parentName, config)
158-
// return
159-
// }
160150

161151
// TODO: Convert to meow.
162152
const yargv = {

src/commands/config/cmd-config-get.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('socket config get', async () => {
6969
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
7070
|_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: <redacted>
7171
72-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m:
72+
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
7373
7474
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)"
7575
`)

src/commands/config/cmd-config-set.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('socket config get', async () => {
7474
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
7575
|_____|___|___|_,_|___|_|.dev | Command: \`socket config set\`, cwd: <redacted>
7676
77-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m:
77+
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
7878
7979
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)
8080

src/commands/config/cmd-config-unset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('socket config unset', async () => {
6969
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
7070
|_____|___|___|_,_|___|_|.dev | Command: \`socket config unset\`, cwd: <redacted>
7171
72-
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m:
72+
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[1m\\x1b[37m Input error: \\x1b[39m\\x1b[22m\\x1b[49m \\x1b[1mPlease review the input requirements and try again\\x1b[22m
7373
7474
- Config key should be the first arg (\\x1b[31mmissing\\x1b[39m)"
7575
`)

0 commit comments

Comments
 (0)