* Executes the provided commands array. This method initializes hooks, invokes * the commands, and handles any exceptions that occur during command execution. * If an exception occurs, it triggers the error hooks and rethrows the exception. * After successful execution or error handling, it
(commandsArray)
| 974 | * execution of error or finalize hooks. |
| 975 | */ |
| 976 | async run(commandsArray) { |
| 977 | this.commandRunStartTime = Date.now() |
| 978 | if (this.serverless.processedInput.commands[0] !== 'plugin') { |
| 979 | // first initialize hooks |
| 980 | for (const { hook } of this.hooks.initialize || []) await hook() |
| 981 | } |
| 982 | |
| 983 | try { |
| 984 | await this.invoke(commandsArray) |
| 985 | } catch (commandException) { |
| 986 | try { |
| 987 | for (const { hook } of this.hooks.error || []) |
| 988 | await hook(commandException) |
| 989 | } catch (errorHookException) { |
| 990 | const errorHookExceptionMeta = tokenizeException(errorHookException) |
| 991 | log.warning( |
| 992 | `The "error" hook crashed with:\n${ |
| 993 | errorHookExceptionMeta.stack || errorHookExceptionMeta.message |
| 994 | }`, |
| 995 | ) |
| 996 | } finally { |
| 997 | throw commandException // eslint-disable-line no-unsafe-finally |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | for (const { hook } of this.hooks.finalize || []) await hook() |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Check if the command is valid. Internally this function will only find |