Skip to content

Commit 54c4231

Browse files
authored
Merge pull request #61 from stainless-api/bruce/better-error-messages
Improve the quality of error message reporting for linting
2 parents f5f25df + 0d3b458 commit 54c4231

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pkg/cmd/dev.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,22 +536,26 @@ func getDiagnostics(ctx context.Context, cmd *cli.Command, cc *apiCommandContext
536536
configPath := cc.workspaceConfig.StainlessConfig
537537
if cmd.IsSet("stainless-config") {
538538
configPath = cmd.String("stainless-config")
539+
} else if configPath == "" {
540+
return nil, fmt.Errorf("You must provide a stainless configuration file with `--config /path/to/stainless.yml` or run this command from an initialized workspace.")
539541
}
540542

541543
stainlessConfig, err := os.ReadFile(configPath)
542544
if err != nil {
543-
return nil, err
545+
return nil, fmt.Errorf("Could not read your stainless configuration file:\n%w", err)
544546
}
545547
specParams.Source.StainlessConfig = string(stainlessConfig)
546548

547549
oasPath := cc.workspaceConfig.OpenAPISpec
548550
if cmd.IsSet("openapi-spec") {
549551
oasPath = cmd.String("openapi-spec")
552+
} else if oasPath == "" {
553+
return nil, fmt.Errorf("You must provide an OpenAPI specification with `--oas /path/to/openapi.json` or run this command from an initialized workspace.")
550554
}
551555

552556
openAPISpec, err := os.ReadFile(oasPath)
553557
if err != nil {
554-
return nil, err
558+
return nil, fmt.Errorf("Could not read your stainless configuration file:\n%w", err)
555559
}
556560
specParams.Source.OpenAPISpec = string(openAPISpec)
557561

pkg/cmd/lint.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ func (m lintModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
120120
}
121121

122122
func (m lintModel) View() string {
123-
if m.error != nil {
124-
return fmt.Sprintf("Error: %s\n", m.error)
125-
}
126-
127123
var content string
128-
if m.diagnostics == nil {
124+
if m.error != nil {
125+
content = "Linting failed!"
126+
} else if m.diagnostics == nil {
129127
content = m.spinner.View() + " Linting"
130128
} else {
131129
content = ViewDiagnosticsPrint(m.diagnostics, -1)

0 commit comments

Comments
 (0)