Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
print errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Nov 23, 2023
1 parent 4f59b45 commit d48d40a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
65 changes: 56 additions & 9 deletions cmd/sst/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
var urnRegex = regexp.MustCompile(`\/[^:]+`)

type Progress struct {
Color color.Attribute
Label string
URN string
Color color.Attribute
Label string
URN string
Message string
time.Duration
}

Expand All @@ -38,11 +39,15 @@ func progress(events project.StackEventStream) {
if progress.Duration != 0 {
color.New(color.FgHiBlack).Printf(" (%s)", progress.Duration)
}
if progress.Message != "" {
color.New(color.FgHiBlack).Print(" ", progress.Message)
}
fmt.Println()
spin.Enable()
}

timing := make(map[string]time.Time)
errors := make(map[string]string)
outputs := make(map[string]interface{})

for evt := range events {
Expand All @@ -52,11 +57,13 @@ func progress(events project.StackEventStream) {
spin.Enable()
continue
}

if evt.ResourcePreEvent != nil {
timing[evt.ResourcePreEvent.Metadata.URN] = time.Now()
if evt.ResourcePreEvent.Metadata.Type == "pulumi:pulumi:Stack" {
continue
}

if evt.ResourcePreEvent.Metadata.Op == apitype.OpSame {
printProgress(Progress{
Color: color.FgHiBlack,
Expand Down Expand Up @@ -85,6 +92,16 @@ func progress(events project.StackEventStream) {
continue
}

if evt.ResourcePreEvent.Metadata.Op == apitype.OpReplace {
printProgress(Progress{
Color: color.FgYellow,
Label: "Updating",
URN: evt.ResourcePreEvent.Metadata.URN,
})

continue
}

if evt.ResourcePreEvent.Metadata.Op == apitype.OpDelete {
printProgress(Progress{
Color: color.FgYellow,
Expand Down Expand Up @@ -129,16 +146,46 @@ func progress(events project.StackEventStream) {
})
}
}

if evt.ResOpFailedEvent != nil {
}

if evt.DiagnosticEvent != nil {
if strings.HasPrefix(evt.DiagnosticEvent.Prefix, "error") && evt.DiagnosticEvent.URN != "" {
splits := strings.Split(evt.DiagnosticEvent.Message, "\n")
splits = strings.Split(splits[1], ":")
error := strings.TrimSpace(splits[len(splits)-1])
errors[evt.DiagnosticEvent.URN] = error
printProgress(Progress{
URN: evt.DiagnosticEvent.URN,
Color: color.FgRed,
Label: "Error ",
Message: error,
})
}
}
}

spin.Stop()
color.New(color.FgGreen, color.Bold).Print("\n✔")
color.New(color.FgWhite, color.Bold).Println(" Deployed:")

for k, v := range outputs {
color.New(color.FgHiBlack).Print(" ")
color.New(color.FgHiBlack, color.Bold).Print(k + ": ")
color.New(color.FgWhite).Println(v)
if len(errors) == 0 {
color.New(color.FgGreen, color.Bold).Print("\n✔")
color.New(color.FgWhite, color.Bold).Println(" Deployed:")

for k, v := range outputs {
color.New(color.FgHiBlack).Print(" ")
color.New(color.FgHiBlack, color.Bold).Print(k + ": ")
color.New(color.FgWhite).Println(v)
}
} else {
color.New(color.FgRed, color.Bold).Print("\n❌")
color.New(color.FgWhite, color.Bold).Println(" Failed:")

for k, v := range errors {
color.New(color.FgHiBlack).Print(" ")
color.New(color.FgRed, color.Bold).Print(formatURN(k) + ": ")
color.New(color.FgWhite).Println(v)
}
}

}
4 changes: 3 additions & 1 deletion examples/test-old/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default {
},
stacks(app) {
app.stack(function Default(ctx) {
// const b = new CfnBucket(ctx.stack, "MyBucket");
const b = new CfnBucket(ctx.stack, "MyBucket", {
bucketName: "sst",
});
ctx.stack.addOutputs({
// url: b.attrDomainName,
});
Expand Down
4 changes: 3 additions & 1 deletion examples/test/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default {
};
},
async run() {
const bucket = new aws.s3.Bucket("my-bucket");
const bucket = new aws.s3.Bucket("my-bucket", {
bucket: "sst",
});
return {
url: util.interpolate`https://${bucket.bucketDomainName}`,
};
Expand Down
3 changes: 3 additions & 0 deletions internal/components/src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LocalWorkspace } from "@pulumi/pulumi/automation";

const stack = await LocalWorkspace.createStack({});
2 changes: 1 addition & 1 deletion pkg/js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type EvalMessage struct {
func (p *Process) Eval(input EvalOptions) error {
outfile := filepath.Join(input.Dir,
"eval",
fmt.Sprintf("eval-%x.mjs", time.Now().Unix()),
fmt.Sprintf("eval-%x.mjs", time.Now().UnixMilli()),
)
slog.Info("esbuild building")
result := esbuild.Build(esbuild.BuildOptions{
Expand Down
18 changes: 11 additions & 7 deletions pkg/project/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *stack) runtime() (string, error) {
},
envVars: {
PULUMI_CONFIG_PASSPHRASE: "",
PULUMI_SKIP_UPDATE_CHECK: "true",
PULUMI_EXPERIMENTAL: "1",
PULUMI_SKIP_CHECKPOINTS: "true",
NODE_PATH: app.paths.temp + "/node_modules",
Expand Down Expand Up @@ -108,13 +109,16 @@ func (s *stack) run(cmd string) (StackEventStream, error) {
Dir: s.project.PathTemp(),
Code: fmt.Sprintf(`
%v
await stack.%v({
// onOutput: (line) => console.log(new Date().toISOString(), line),
onEvent: (evt) => {
console.log("~e" + JSON.stringify(evt))
// console.log(JSON.stringify(evt, null, 4))
},
})
try {
const result = await stack.%v({
// onOutput: (line) => console.log(new Date().toISOString(), line),
logVerbosity: 0,
onEvent: (evt) => {
console.log("~e" + JSON.stringify(evt))
},
})
} catch (e) {
}
`, stack, cmd),
})
if err != nil {
Expand Down

0 comments on commit d48d40a

Please sign in to comment.