Skip to content

Commit

Permalink
Merge pull request #956 from hashicorp/decode-stack-diagnostics-tryin…
Browse files Browse the repository at this point in the history
…g-brandonc-suggestion

Stacks: Decode diagnostics
  • Loading branch information
DanielMSchmidt authored Aug 12, 2024
2 parents fd766c1 + 0c1f98e commit b585e79
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
1 change: 1 addition & 0 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type StackConfiguration struct {
Components []*StackComponent `jsonapi:"attr,components"`
ErrorMessage *string `jsonapi:"attr,error-message"`
EventStreamURL string `jsonapi:"attr,event-stream-url"`
Diagnostics []*StackDiagnostic `jsonapi:"attr,diags"`
}

// StackDeployment represents a stack deployment, specified by configuration
Expand Down
45 changes: 45 additions & 0 deletions stack_diagnostic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tfe

// StackDiagnostic represents any sourcebundle.Diagnostic value. The simplest form has
// just a severity, single line summary, and optional detail. If there is more
// information about the source of the diagnostic, this is represented in the
// range field.
type StackDiagnostic struct {
Severity string `jsonapi:"attr,severity"`
Summary string `jsonapi:"attr,summary"`
Detail string `jsonapi:"attr,detail"`
Range *DiagnosticRange `jsonapi:"attr,range"`
}

// DiagnosticPos represents a position in the source code.
type DiagnosticPos struct {
// Line is a one-based count for the line in the indicated file.
Line int `jsonapi:"attr,line"`

// Column is a one-based count of Unicode characters from the start of the line.
Column int `jsonapi:"attr,column"`

// Byte is a zero-based offset into the indicated file.
Byte int `jsonapi:"attr,byte"`
}

// DiagnosticRange represents the filename and position of the diagnostic
// subject. This defines the range of the source to be highlighted in the
// output. Note that the snippet may include additional surrounding source code
// if the diagnostic has a context range.
//
// The stacks-specific source field represents the full source bundle address
// of the file, while the filename field is the sub path relative to its
// enclosing package. This represents an attempt to be somewhat backwards
// compatible with the existing Terraform JSON diagnostic format, where
// filename is root module relative.
//
// The Start position is inclusive, and the End position is exclusive. Exact
// positions are intended for highlighting for human interpretation only and
// are subject to change.
type DiagnosticRange struct {
Filename string `jsonapi:"attr,filename"`
Source string `jsonapi:"attr,source"`
Start DiagnosticPos `jsonapi:"attr,start"`
End DiagnosticPos `jsonapi:"attr,end"`
}
16 changes: 8 additions & 8 deletions stack_plan_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ type stackPlanOperations struct {
var _ StackPlanOperations = &stackPlanOperations{}

type StackPlanOperation struct {
ID string `jsonapi:"primary,stack-plan-operations"`
Type string `jsonapi:"attr,operation-type"`
Status string `jsonapi:"attr,status"`
EventStreamURL string `jsonapi:"attr,event-stream-url"`
Diagnostics string `jsonapi:"attr,diags"`
ID string `jsonapi:"primary,stack-plan-operations"`
Type string `jsonapi:"attr,operation-type"`
Status string `jsonapi:"attr,status"`
EventStreamURL string `jsonapi:"attr,event-stream-url"`
Diagnostics []*StackDiagnostic `jsonapi:"attr,diags"`

// Relations
StackPlan *StackPlan `jsonapi:"relation,stack-plan"`
Expand All @@ -44,13 +44,13 @@ func (s stackPlanOperations) Read(ctx context.Context, stackPlanOperationID stri
return nil, err
}

ucs := &StackPlanOperation{}
err = req.Do(ctx, ucs)
spo := &StackPlanOperation{}
err = req.Do(ctx, spo)
if err != nil {
return nil, err
}

return ucs, nil
return spo, nil
}

func (s stackPlanOperations) DownloadEventStream(ctx context.Context, eventStreamURL string) ([]byte, error) {
Expand Down

0 comments on commit b585e79

Please sign in to comment.