@@ -14,7 +14,7 @@ import { PlayoutModel, PlayoutModelPreInit } from './model/PlayoutModel.js'
1414import { runJobWithPlaylistLock } from './lock.js'
1515import { updateTimeline } from './timeline/generate.js'
1616import { performTakeToNextedPart } from './take.js'
17- import { ActionUserData } from '@sofie-automation/blueprints-integration'
17+ import { ActionUserData , BlueprintExecuteActionResult } from '@sofie-automation/blueprints-integration'
1818import {
1919 DBRundownPlaylist ,
2020 SelectedPartInstance ,
@@ -38,6 +38,7 @@ import type { INoteBase } from '@sofie-automation/corelib/dist/dataModel/Notes'
3838import { NotificationsModelHelper } from '../notifications/NotificationsModelHelper.js'
3939import type { INotificationsModel } from '../notifications/NotificationsModel.js'
4040import { PersistentPlayoutStateStore } from '../blueprints/context/services/PersistantStateStore.js'
41+ import { interpollateTranslation } from '@sofie-automation/corelib/dist/TranslatableMessage'
4142
4243/**
4344 * Execute an AdLib Action
@@ -249,7 +250,7 @@ export async function executeActionInner(
249250 ) } (${ actionParameters . triggerMode } )`
250251 )
251252
252- let result : ExecuteActionResult | void
253+ let result : BlueprintExecuteActionResult | void
253254
254255 try {
255256 const blueprintPersistentState = new PersistentPlayoutStateStore (
@@ -274,15 +275,21 @@ export async function executeActionInner(
274275 throw UserError . fromUnknown ( err )
275276 }
276277
277- if ( result && result . validationErrors ) {
278+ // If the blueprint returned an error, abort the action and throw the error
279+ if ( result && typeof result === 'object' && result . message ) {
280+ const messageStr = interpollateTranslation ( result . message . key , result . message . args )
281+ const statusCode = Number . isFinite ( result . errorCode )
282+ ? Math . max ( Math . min ( Math . round ( result . errorCode as number ) , 499 ) , 400 )
283+ : 409
278284 throw UserError . from (
279- new Error (
280- `AdLib Action "${ actionParameters . actionId } " validation failed: ${ JSON . stringify ( result . validationErrors ) } `
281- ) ,
285+ new Error ( messageStr ) ,
282286 UserErrorMessage . ValidationFailed ,
283- undefined ,
284- 409
287+ { message : messageStr , rawMessage : result . message , details : result . details } ,
288+ statusCode
285289 )
290+ } else if ( result !== undefined ) {
291+ // Unexpected return value — does not match the BlueprintExecuteActionResult shape; treat as success but warn so it can be investigated
292+ logger . warn ( `executeAction returned an unexpected value: ${ JSON . stringify ( result ) } ` )
286293 }
287294
288295 // Store any notes generated by the action
0 commit comments