File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { getPublicApiToken, setupSdk } from './sdk.mts'
1111import { addArtifactToAlertsMap } from './socket-package-alert.mts'
1212
1313import type { CompactSocketArtifact } from './alert/artifact.mts'
14+ import type { FoundSocketYml } from './config.mts'
1415import type { AlertFilter , AlertsByPurl } from './socket-package-alert.mts'
1516import type { LockfileObject } from '@pnpm/lockfile.fs'
1617import type { Spinner } from '@socketsecurity/registry/lib/spinner'
@@ -83,7 +84,10 @@ export async function getAlertsMapFromPurls(
8384 throw new Error ( 'Auth error: Run `socket login` first' )
8485 }
8586 const sockSdk = sockSdkCResult . data
86- const socketYml = findSocketYmlSync ( ) ?. parsed
87+ const socketYmlResult = findSocketYmlSync ( )
88+ const socketYml = socketYmlResult . ok
89+ ? ( socketYmlResult . data as FoundSocketYml ) . parsed
90+ : undefined
8791
8892 const alertsMapOptions = {
8993 consolidate : opts . consolidate ,
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export type FoundSocketYml = {
111111
112112export function findSocketYmlSync (
113113 dir = process . cwd ( ) ,
114- ) : FoundSocketYml | undefined {
114+ ) : CResult < FoundSocketYml | undefined > {
115115 let prevDir = null
116116 while ( dir !== prevDir ) {
117117 let ymlPath = path . join ( dir , 'socket.yml' )
@@ -123,18 +123,25 @@ export function findSocketYmlSync(
123123 if ( typeof yml === 'string' ) {
124124 try {
125125 return {
126- path : ymlPath ,
127- parsed : config . parseSocketConfig ( yml ) ,
126+ ok : true ,
127+ data : {
128+ path : ymlPath ,
129+ parsed : config . parseSocketConfig ( yml ) ,
130+ } ,
128131 }
129132 } catch ( e ) {
130133 debugDir ( 'inspect' , { error : e } )
131- throw new Error ( `Found file but was unable to parse ${ ymlPath } ` )
134+ return {
135+ ok : false ,
136+ message : `Found file but was unable to parse ${ ymlPath } ` ,
137+ cause : e instanceof Error ? e . message : String ( e ) ,
138+ }
132139 }
133140 }
134141 prevDir = dir
135142 dir = path . join ( dir , '..' )
136143 }
137- return undefined
144+ return { ok : true , data : undefined }
138145}
139146
140147export function getConfigValue < Key extends keyof LocalConfig > (
You can’t perform that action at this time.
0 commit comments