fix(automate): better handle trigger definition errors (#4845)
This commit is contained in:
@@ -10,7 +10,12 @@ import {
|
||||
getFunctionReleaseFactory,
|
||||
getFunctionReleasesFactory
|
||||
} from '@/modules/automate/clients/executionEngine'
|
||||
import { Automate, Roles, removeNullOrUndefinedKeys } from '@speckle/shared'
|
||||
import {
|
||||
Automate,
|
||||
Roles,
|
||||
ensureError,
|
||||
removeNullOrUndefinedKeys
|
||||
} from '@speckle/shared'
|
||||
import { AuthCodePayloadAction } from '@/modules/automate/services/authCode'
|
||||
import {
|
||||
ProjectAutomationCreateInput,
|
||||
@@ -52,6 +57,7 @@ import { GetBranchesByIds } from '@/modules/core/domain/branches/operations'
|
||||
import { ValidateStreamAccess } from '@/modules/core/domain/streams/operations'
|
||||
import { EventBusEmit } from '@/modules/shared/services/eventBus'
|
||||
import { AutomationEvents } from '@/modules/automate/domain/events'
|
||||
import { UnformattableTriggerDefinitionSchemaError } from '@speckle/shared/dist/commonjs/automate/index.js'
|
||||
|
||||
export type CreateAutomationDeps = {
|
||||
createAuthCode: CreateStoredAuthCode
|
||||
@@ -395,9 +401,20 @@ export const createAutomationRevisionFactory =
|
||||
userResourceAccessRules
|
||||
)
|
||||
|
||||
const triggers = Automate.AutomateTypes.formatTriggerDefinitionSchema(
|
||||
input.triggerDefinitions
|
||||
)
|
||||
let triggers: Automate.AutomateTypes.TriggerDefinitionsSchema
|
||||
try {
|
||||
triggers = Automate.AutomateTypes.formatTriggerDefinitionSchema(
|
||||
input.triggerDefinitions
|
||||
)
|
||||
} catch (e) {
|
||||
if (e instanceof UnformattableTriggerDefinitionSchemaError) {
|
||||
throw new AutomationRevisionCreationError(
|
||||
'One or more trigger definitions are not valid',
|
||||
{ cause: ensureError(e, 'Unknown error when formatting trigger definition') }
|
||||
)
|
||||
}
|
||||
throw e
|
||||
}
|
||||
const triggerDefinitions = triggers.definitions.map((d) => {
|
||||
if (Automate.AutomateTypes.isVersionCreatedTriggerDefinition(d)) {
|
||||
const triggerDef: InsertableAutomationRevisionTrigger = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
AutomationCreationError,
|
||||
AutomationRevisionCreationError,
|
||||
AutomationUpdateError
|
||||
} from '@/modules/automate/errors/management'
|
||||
import {
|
||||
@@ -406,10 +407,7 @@ const buildAutomationUpdate = () => {
|
||||
})
|
||||
)
|
||||
|
||||
expect(
|
||||
e instanceof Automate.UnformattableTriggerDefinitionSchemaError,
|
||||
e.toString()
|
||||
).to.be.true
|
||||
expect(e instanceof AutomationRevisionCreationError, e.toString()).to.be.true
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user