Skip to content

Commit f09ed6f

Browse files
committed
fix: use GetWithError instead of only Get when accessing sast settings in gaf config
1 parent 5d0415a commit f09ed6f

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Right now the language server supports the following actions:
338338
- `SettingsSastEnabled` triggers the api call to check if Snyk Code is enabled
339339
- command: `snyk.getSettingsSastEnabled`
340340
- args: empty
341-
- returns `true` if enabled, `false` if not, or an error and false if an error occurred
341+
- returns a `*sast_contract.SastResponse` or, or an error and false if an error occurred
342342
- `GetActiveUser` triggers the api call to get the active logged in user or an error if not logged in
343343
- command: `snyk.getActiveUser`
344344
- args: empty

domain/ide/command/sast_enabled.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func (cmd *sastEnabled) Execute(_ context.Context) (any, error) {
4848
}
4949

5050
gafConfig := cmd.c.Engine().GetConfiguration()
51-
sastResponse := gafConfig.Get(code_workflow.ConfigurationSastSettings)
51+
sastResponse, err := gafConfig.GetWithError(code_workflow.ConfigurationSastSettings)
52+
if err != nil {
53+
return nil, err
54+
}
5255

5356
return sastResponse, nil
5457
}

infrastructure/code/code.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333
codeClient "github.com/snyk/code-client-go"
3434
codeClientObservability "github.com/snyk/code-client-go/observability"
3535
"github.com/snyk/code-client-go/scan"
36+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
37+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
3638
"github.com/snyk/go-application-framework/pkg/utils"
3739

3840
"github.com/snyk/snyk-ls/internal/types"
@@ -46,9 +48,6 @@ import (
4648
"github.com/snyk/snyk-ls/internal/product"
4749
"github.com/snyk/snyk-ls/internal/progress"
4850
"github.com/snyk/snyk-ls/internal/uri"
49-
50-
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
51-
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
5251
)
5352

5453
type ScanStatus struct {
@@ -152,7 +151,16 @@ func (sc *Scanner) Scan(ctx context.Context, path types.FilePath, folderPath typ
152151
}
153152

154153
gafConfig := sc.C.Engine().GetConfiguration()
155-
sastResponse, ok := gafConfig.Get(code_workflow.ConfigurationSastSettings).(*sast_contract.SastResponse)
154+
155+
response, err := gafConfig.GetWithError(code_workflow.ConfigurationSastSettings)
156+
if err != nil {
157+
return nil, err
158+
}
159+
160+
sastResponse, ok := response.(*sast_contract.SastResponse)
161+
if !ok {
162+
return nil, errors.New("Failed to get the sast settings")
163+
}
156164

157165
if sastResponse == nil || !ok {
158166
return issues, errors.New("Failed to get the sast settings")

0 commit comments

Comments
 (0)