Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike: transfer data via filesystem for TS <=> Go #5626

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,30 @@ import (
"github.com/snyk/cli-extension-sbom/pkg/sbom"
"github.com/snyk/cli/cliv2/internal/cliv2"
"github.com/snyk/cli/cliv2/internal/constants"
cli_errors "github.com/snyk/cli/cliv2/internal/errors"
"github.com/snyk/cli/cliv2/pkg/basic_workflows"
"github.com/snyk/container-cli/pkg/container"
"github.com/snyk/error-catalog-golang-public/snyk_errors"
"github.com/snyk/go-application-framework/pkg/analytics"
"github.com/snyk/go-application-framework/pkg/app"
"github.com/snyk/go-application-framework/pkg/configuration"
"github.com/snyk/go-application-framework/pkg/instrumentation"
"github.com/snyk/go-application-framework/pkg/local_workflows/network_utils"
"github.com/snyk/go-application-framework/pkg/local_workflows/output_workflow"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
"github.com/snyk/go-application-framework/pkg/local_workflows/content_type"
"github.com/snyk/go-application-framework/pkg/local_workflows/json_schemas"
"github.com/snyk/go-application-framework/pkg/local_workflows/network_utils"
"github.com/snyk/go-application-framework/pkg/local_workflows/output_workflow"
"github.com/snyk/go-application-framework/pkg/networking"
"github.com/snyk/go-application-framework/pkg/runtimeinfo"
"github.com/snyk/go-application-framework/pkg/ui"
"github.com/snyk/go-application-framework/pkg/utils"
"github.com/snyk/go-application-framework/pkg/workflow"
"github.com/snyk/go-httpauth/pkg/httpauth"
"github.com/snyk/snyk-iac-capture/pkg/capture"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

snykls "github.com/snyk/snyk-ls/ls_extension"

cli_errors "github.com/snyk/cli/cliv2/internal/errors"
"github.com/snyk/cli/cliv2/pkg/basic_workflows"
)

var internalOS string
Expand Down Expand Up @@ -621,6 +620,36 @@ func MainWithErrorCode() int {
cliAnalytics.GetInstrumentation().SetStatus(analytics.Failure)
}

// Load error out of run-errors.json
filePath := globalConfiguration.GetString(configuration.TEMP_DIR_PATH) + "/typescript-runtime-errors"

// Read the entire file into a byte slice
errDataFromFile, err := os.ReadFile(filePath)
if err != nil {
globalLogger.Printf("Failed to read file: %v", err)
}

// Convert the byte slice to a string and print it
fmt.Println(`LADEBUG`)
fmt.Println(string(errDataFromFile))
cliError := snyk_errors.Error{
ID: uuid.NewString(),
Title: "Unable to set environment",
Description: "The specified environment cannot be used. As a result, the configuration remains unchanged.Provide the correct specifications for the environment and try again.",
StatusCode: 200,
ErrorCode: string(errDataFromFile),
Classification: "ACTIONABLE",
Links: []string{
"https://docs.snyk.io/snyk-cli/commands/config-environment",
},
Level: "error",
Detail: string(errDataFromFile),
}
cliAnalytics.GetInstrumentation().AddError(
cliError,
)
// END error loading

if !globalConfiguration.GetBool(configuration.ANALYTICS_DISABLED) {
sendAnalytics(cliAnalytics, globalLogger)
}
Expand Down
5 changes: 4 additions & 1 deletion cliv2/pkg/basic_workflows/legacycli.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ func legacycliWorkflow(
if len(apiToken) == 0 {
apiToken = "random"
}
cli.AppendEnvironmentVariables([]string{constants.SNYK_API_TOKEN_ENV + "=" + apiToken})
cli.AppendEnvironmentVariables([]string{
constants.SNYK_API_TOKEN_ENV + "=" + apiToken,
"SNYK_TEMP_DIR_PATH=" + config.GetString(configuration.TEMP_DIR_PATH),
})

err = cli.Init()
if err != nil {
Expand Down
11 changes: 1 addition & 10 deletions src/cli/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,7 @@ export default async function test(

if (notSuccess) {
response += chalk.bold.red(summaryMessage);
const error = new Error(response) as any;
// take the code of the first problem to go through error
// translation
// HACK as there can be different errors, and we pass only the
// first one
error.code = errorResults[0].code;
error.userMessage = errorResults[0].userMessage;
error.strCode = errorResults[0].strCode;
error.innerError = errorResults[0].innerError;
throw error;
throw errorResults[0];
}

if (foundVulnerabilities) {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ async function handleError(args, error) {
analytics.add('error', true);
analytics.add('command', args.command);
} else {
const errorFilePath = pathLib.join(process.env.SNYK_TEMP_DIR_PATH || getFullPath(''), './typescript-runtime-errors');

// TODO: If error is NOT valid error catalog message transform to match structure
await saveJsonResultsToFile(JSON.stringify(
analyticsError,
), errorFilePath);
analytics.add('error-message', analyticsError.message);
// Note that error.stack would also contain the error message
// (see https://nodejs.org/api/errors.html#errors_error_stack)
Expand Down
Loading