Skip to content

Commit 537343e

Browse files
authored
Fix emitting warning status logs as visible messages (#445)
pulumi package add terraform module ... used to print "Using Terraform CLI for schema inference" to stdout. This is now fixed. The root cause is that DEBUG level messages were sent at INFO level to the engine on the wire by mistake.
1 parent cf725b5 commit 537343e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

pkg/modprovider/logger.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,15 @@ func (l *resourceLogger) Log(ctx context.Context, level tfsandbox.LogLevel, mess
113113
return
114114
}
115115

116-
var err error
117-
var diagLevel diag.Severity
118-
switch level {
119-
case tfsandbox.Debug:
120-
diagLevel = diag.Debug
121-
case tfsandbox.Info:
122-
diagLevel = diag.Info
123-
case tfsandbox.Warn:
124-
diagLevel = diag.Warning
125-
case tfsandbox.Error:
126-
diagLevel = diag.Error
127-
default:
128-
diagLevel = diag.Info
129-
}
116+
diagLevel := asSeverity(level)
130117

131118
if diagLevel == diag.Error && isMissingCredentialsErrorFromAWS(message) {
132119
// for AWS provider, we can detect missing credentials errors and provide a more helpful message
133120
// that is specific to Pulumi users.
134121
message = awsMissingCredentialsErrorMessage
135122
}
136123

137-
err = l.hc.Log(ctx, diagLevel, l.urn, message)
138-
124+
err := l.hc.Log(ctx, diagLevel, l.urn, message)
139125
contract.IgnoreError(err)
140126
}
141127

@@ -144,20 +130,30 @@ func (l *resourceLogger) LogStatus(ctx context.Context, level tfsandbox.LogLevel
144130
return
145131
}
146132

147-
var err error
133+
// warnings and errors should not be Status messages
134+
switch level {
135+
case tfsandbox.Warn, tfsandbox.Error:
136+
l.Log(ctx, level, message)
137+
return
138+
}
139+
140+
err := l.hc.LogStatus(ctx, asSeverity(level), l.urn, message)
141+
contract.IgnoreError(err)
142+
}
143+
144+
func asSeverity(level tfsandbox.LogLevel) diag.Severity {
148145
var diagLevel diag.Severity
149146
switch level {
147+
case tfsandbox.Debug:
148+
diagLevel = diag.Debug
150149
case tfsandbox.Info:
151150
diagLevel = diag.Info
152151
case tfsandbox.Warn:
152+
diagLevel = diag.Warning
153153
case tfsandbox.Error:
154-
l.Log(ctx, level, message)
155-
return
154+
diagLevel = diag.Error
156155
default:
157156
diagLevel = diag.Info
158157
}
159-
160-
err = l.hc.LogStatus(ctx, diagLevel, l.urn, message)
161-
162-
contract.IgnoreError(err)
158+
return diagLevel
163159
}

0 commit comments

Comments
 (0)