{"record":{"id":"340b5650046a4465","repo":"passbolt/passbolt_api","slug":"exception-getmessage-ignorecreatecommand","errorCode":null,"errorMessage":"$exception->getMessage()","messagePattern":"\\$exception->getMessage\\(\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Command/IgnoreCreateCommand.php","lineNumber":73,"sourceCode":"\n        $this->pad = 0;\n        $foreignModel = $args->getOption('model');\n        $foreignKey = $args->getOption('id');\n\n        if (!Validation::inList($foreignModel, ['Groups', 'Users', 'DirectoryEntries'])) {\n            $io->error(__('The record model is not valid.'));\n\n            return $this->errorCode();\n        }\n        try {\n            /** @var \\Passbolt\\DirectorySync\\Model\\Table\\DirectoryIgnoreTable $DirectoryIgnore */\n            $DirectoryIgnore = TableRegistry::getTableLocator()->get('Passbolt/DirectorySync.DirectoryIgnore');\n            $DirectoryIgnore->createOrFail($foreignModel, $foreignKey);\n            $this->success(__('The record will be ignored in the next directory synchronization.'), $io);\n\n            return $this->successCode();\n        } catch (ValidationException $exception) {\n            $io->err($exception->getMessage());\n            $this->displayValidationError($exception->getEntity()->getErrors(), $io);\n\n            return $this->errorCode();\n        } catch (Exception $exception) {\n            $io->err($exception->getMessage());\n\n            return $this->errorCode();\n        }\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":84,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Command/IgnoreCreateCommand.php#L55-L84","documentation":"IgnoreCreateCommand creates a DirectoryIgnore record so an entity is skipped in future LDAP syncs. ValidationException (e.g. invalid foreign model/id, record already ignored) is caught separately: the message is printed and the validation errors of the failed entity are displayed via displayValidationError(), returning an error code.","triggerScenarios":"Running `passbolt directory_sync ignore --create ...` with options that fail DirectoryIgnore entity validation — missing/invalid model or foreign key, malformed UUID, or creating a duplicate ignore entry.","commonSituations":"Typo in the --model option value; passing a non-UUID id; trying to ignore an entity that is already ignored.","solutions":["Read the displayed validation error list to see which field failed.","Ensure --model is one of Users, Groups, DirectoryEntries.","Pass a valid UUID for --id.","Check the entity is not already ignored (duplicate create).","Re-run the command with corrected options."],"exampleFix":"// before\n$io->err($exception->getMessage());\n$this->displayValidationError($exception->getEntity()->getErrors(), $io);\n// after\n$io->err('Cannot create ignore record: invalid options provided.');\n$this->displayValidationError($exception->getEntity()->getErrors(), $io);\n$io->out('Usage: passbolt directory_sync ignore --create --model=Users --id=<uuid>');","handlingStrategy":"validation","validationCode":"$allowed = ['Users', 'Groups', 'DirectoryEntries'];\nif (!in_array($foreignModel, $allowed, true)) {\n    throw new \\InvalidArgumentException(\"--model must be one of: \" . implode(', ', $allowed));\n}\nif (!\\Cake\\Validation\\Validation::uuid($foreignKey)) {\n    throw new \\InvalidArgumentException('--id must be a valid UUID');\n}","typeGuard":"function isValidIgnoreTarget(string $model, string $id): bool {\n    return in_array($model, ['Users', 'Groups', 'DirectoryEntries'], true)\n        && \\Cake\\Validation\\Validation::uuid($id);\n}","tryCatchPattern":"try {\n    $DirectoryIgnore->createOrFail($foreignModel, $foreignKey);\n} catch (\\Cake\\Datasource\\Exception\\RecordNotFoundException $e) {\n    // entity already gone — treat as success\n} catch (\\Cake\\Datasource\\Validation\\ValidationException $e) {\n    $this->displayValidationError($e->getEntity()->getErrors(), $io);\n}","preventionTips":["Validate model/id options against the allowed list before invoking.","Check the entity is not already ignored to avoid duplicate creates.","Use UUID validation on all --id inputs.","Consult DirectoryIgnore table contents before scripting bulk ignores."],"tags":["ldap","directory-sync","validation","cli"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}