Skip to content

Commit

Permalink
better error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Feb 28, 2024
1 parent 07bb377 commit 991159d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
11 changes: 7 additions & 4 deletions cmd/sst/ui/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ func parseError(input string) []string {

if strings.Contains(input, "occurred:") {
lines := []string{}
for _, line := range strings.Split(input, "\n") {
sections := strings.Split(input, "*")
for _, line := range sections[1:] {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "*") {
splits := strings.Split(line, ":")
lines = append(lines, strings.TrimSpace(splits[len(splits)-1]))
splits := strings.Split(line, ":")
final := strings.TrimSpace(splits[len(splits)-1])

for _, split := range strings.Split(final, "\n") {
lines = append(lines, split)
}
}
return lines
Expand Down
14 changes: 9 additions & 5 deletions cmd/sst/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (u *UI) Trigger(evt *project.StackEvent) {
Color: color.FgRed,
Final: true,
Label: "Error",
Message: parseError(evt.DiagnosticEvent.Message)[0],
Message: parseError(evt.DiagnosticEvent.Message),
})
}

Expand Down Expand Up @@ -338,7 +338,7 @@ func (u *UI) Trigger(evt *project.StackEvent) {
if status.URN != "" {
color.New(color.FgRed, color.Bold).Println(" " + formatURN(status.URN))
}
color.New(color.FgWhite).Println(strings.Join(parseError(status.Message), "\n"))
color.New(color.FgWhite).Println(" " + strings.Join(parseError(status.Message), "\n "))
}
}
}
Expand Down Expand Up @@ -488,7 +488,7 @@ type Progress struct {
Label string
URN string
Final bool
Message string
Message []string
time.Duration
}

Expand Down Expand Up @@ -516,8 +516,12 @@ func (u *UI) printProgress(progress Progress) {
if progress.Duration != 0 {
color.New(color.FgHiBlack).Printf(" (%s)", progress.Duration)
}
if progress.Message != "" {
color.New(color.FgHiBlack).Print(progress.Message)
if len(progress.Message) > 0 {
for _, item := range progress.Message {
fmt.Println()
color.New(progress.Color, color.Bold).Print("| ")
color.New(color.FgWhite).Print(item)
}
}
fmt.Println()
u.hasProgress = true
Expand Down
8 changes: 3 additions & 5 deletions examples/test/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export default $config({
};
},
async run() {
const fn = new sst.aws.Function("MyFunction", {
handler: "src/index.handler",
});
new aws.s3.Bucket("MyBucket", {
bucket: "my-bucket",
new aws.dynamodb.Table("Web", {
name: "/aweofih",
billingMode: "PAY_PER_REQUEST",
});
return {};
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/project/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,19 @@ func (s *stack) Run(ctx context.Context, input *StackInput) error {
if !ok {
return
}
input.OnEvent(&StackEvent{EngineEvent: event})

if event.DiagnosticEvent != nil && event.DiagnosticEvent.Severity == "error" {
if strings.HasPrefix(event.DiagnosticEvent.Message, "update failed") {
break
}
complete.Errors = append(complete.Errors, Error{
Message: event.DiagnosticEvent.Message,
URN: event.DiagnosticEvent.URN,
})
}

input.OnEvent(&StackEvent{EngineEvent: event})

if event.SummaryEvent != nil {
complete.Finished = true
}
Expand Down

0 comments on commit 991159d

Please sign in to comment.