-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2334 from posit-dev/mnv-preflight-errs-on-deploy
Deployment preflight errors due to bad content GUID
- Loading branch information
Showing
18 changed files
with
441 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (C) 2024 by Posit Software, PBC. | ||
|
||
import { describe, expect, test } from "vitest"; | ||
import { EventStreamMessage } from "./api"; | ||
import { | ||
EventStreamMessageErrorCoded, | ||
isCodedEventErrorMessage, | ||
isEvtErrDeploymentFailed, | ||
handleEventCodedError, | ||
} from "./eventErrors"; | ||
import { ErrorCode } from "./utils/errorTypes"; | ||
|
||
function mkEventStreamMsg(data: Record<PropertyKey, any>): EventStreamMessage; | ||
function mkEventStreamMsg( | ||
data: Record<PropertyKey, any>, | ||
errCode: ErrorCode, | ||
): EventStreamMessageErrorCoded; | ||
function mkEventStreamMsg(data: Record<PropertyKey, any>, errCode?: ErrorCode) { | ||
const smsg: EventStreamMessage = { | ||
type: "publish/failure", | ||
time: "Tue Oct 01 2024 10:00:00 GMT-0600", | ||
data, | ||
error: "failed to publish", | ||
}; | ||
if (errCode) { | ||
smsg.errCode = errCode; | ||
} | ||
return smsg; | ||
} | ||
|
||
describe("Event errors", () => { | ||
test("isCodedEventErrorMessage", () => { | ||
// Message without error code | ||
let streamMsg = mkEventStreamMsg({}); | ||
let result = isCodedEventErrorMessage(streamMsg); | ||
expect(result).toBe(false); | ||
|
||
// Message with error code | ||
streamMsg = mkEventStreamMsg({}, "deployFailed"); | ||
result = isCodedEventErrorMessage(streamMsg); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("isEvtErrDeploymentFailed", () => { | ||
// Message with another error code | ||
let streamMsg = mkEventStreamMsg({}, "unknown"); | ||
let result = isEvtErrDeploymentFailed(streamMsg); | ||
expect(result).toBe(false); | ||
|
||
// Message with error code | ||
streamMsg = mkEventStreamMsg({}, "deployFailed"); | ||
result = isEvtErrDeploymentFailed(streamMsg); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test("handleEventCodedError", () => { | ||
const msgData = { | ||
dashboardUrl: "https://here.it.is/content/abcdefg", | ||
message: "Deployment failed - structured message from the agent", | ||
error: "A possum on the fridge", | ||
}; | ||
let streamMsg = mkEventStreamMsg(msgData, "unknown"); | ||
let resultMsg = handleEventCodedError(streamMsg); | ||
expect(resultMsg).toBe("Unknown error: A possum on the fridge"); | ||
|
||
streamMsg = mkEventStreamMsg(msgData, "deployFailed"); | ||
resultMsg = handleEventCodedError(streamMsg); | ||
expect(resultMsg).toBe( | ||
"Deployment failed - structured message from the agent", | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2024 by Posit Software, PBC. | ||
|
||
import { EventStreamMessage } from "./api/types/events"; | ||
import { ErrorCode } from "./utils/errorTypes"; | ||
|
||
export interface EventStreamMessageErrorCoded<T = Record<string, string>> | ||
extends EventStreamMessage<T> { | ||
errCode: ErrorCode; | ||
} | ||
|
||
export function isCodedEventErrorMessage( | ||
msg: EventStreamMessage, | ||
): msg is EventStreamMessageErrorCoded { | ||
return msg.errCode !== undefined; | ||
} | ||
|
||
type deploymentEvtErr = { | ||
dashboardUrl: string; | ||
localId: string; | ||
message: string; | ||
error: string; | ||
}; | ||
|
||
export const isEvtErrDeploymentFailed = ( | ||
emsg: EventStreamMessageErrorCoded, | ||
): emsg is EventStreamMessageErrorCoded<deploymentEvtErr> => { | ||
return emsg.errCode === "deployFailed"; | ||
}; | ||
|
||
export const handleEventCodedError = ( | ||
emsg: EventStreamMessageErrorCoded, | ||
): string => { | ||
if (isEvtErrDeploymentFailed(emsg)) { | ||
return emsg.data.message; | ||
} | ||
|
||
const unknownErrMsg = emsg.data.error || emsg.data.message; | ||
return `Unknown error: ${unknownErrMsg}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package http_client | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/posit-dev/publisher/internal/events" | ||
"github.com/posit-dev/publisher/internal/types" | ||
"github.com/posit-dev/publisher/internal/util/utiltest" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
// Copyright (C) 2024 by Posit Software, PBC. | ||
|
||
type HttpClientSuite struct { | ||
utiltest.Suite | ||
} | ||
|
||
func TestHttpClientSuite(t *testing.T) { | ||
suite.Run(t, new(HttpClientSuite)) | ||
} | ||
|
||
func (s *HttpClientSuite) TestIsHTTPAgentErrorStatusOf() { | ||
agentErr := types.NewAgentError( | ||
events.DeploymentFailedCode, | ||
NewHTTPError("", "", http.StatusNotFound), | ||
nil, | ||
) | ||
|
||
// With a true agent error | ||
resultingErr, yesItIs := IsHTTPAgentErrorStatusOf(agentErr, http.StatusNotFound) | ||
s.Equal(yesItIs, true) | ||
s.Equal(agentErr, resultingErr) | ||
|
||
// With a true agent error, but a status that it is not | ||
resultingErr, yesItIs = IsHTTPAgentErrorStatusOf(agentErr, http.StatusBadGateway) | ||
s.Equal(yesItIs, false) | ||
s.Equal(agentErr, resultingErr) | ||
|
||
// With a non agent error | ||
resultingErr, yesItIs = IsHTTPAgentErrorStatusOf(errors.New("nope"), http.StatusNotFound) | ||
s.Equal(yesItIs, false) | ||
s.Nil(resultingErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.