{"record":{"id":"8c32b654b1c36d28","repo":"instructure/canvas-lms","slug":"unable-to-find-commentbankitem","errorCode":null,"errorMessage":"Unable to find CommentBankItem","messagePattern":"Unable to find CommentBankItem","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/delete_comment_bank_item.rb","lineNumber":29,"sourceCode":"#\n# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n\nclass Mutations::DeleteCommentBankItem < Mutations::BaseMutation\n  graphql_name \"DeleteCommentBankItem\"\n\n  argument :id, ID, required: true, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func(\"CommentBankItem\")\n  field :comment_bank_item_id, ID, null: false\n\n  def resolve(input:)\n    record = CommentBankItem.active.find_by(id: input[:id])\n    raise GraphQL::ExecutionError, I18n.t(\"Unable to find CommentBankItem\") if record.nil?\n\n    verify_authorized_action!(record, :delete)\n    context[:deleted_models][:comment_bank_item] = record\n\n    if record.destroy\n      { comment_bank_item_id: record.id }\n    else\n      raise GraphQL::ExecutionError, I18n.t(\"Unable to delete CommentBankItem\")\n    end\n  end\n\n  def self.comment_bank_item_id_log_entry(_entry, context)\n    context[:deleted_models][:comment_bank_item]\n  end\nend\n","sourceCodeStart":11,"sourceCodeEnd":45,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/delete_comment_bank_item.rb#L11-L45","documentation":"DeleteCommentBankItem#resolve looks up CommentBankItem.active.find_by(id:) and raises GraphQL::ExecutionError \"Unable to find CommentBankItem\" when no active record matches. The lookup is also ID-prepared via relay_or_legacy_id_prepare_func, so malformed ids fail the same way.","triggerScenarios":"Deleting a comment bank item with an id that doesn't exist, was already soft-deleted, belongs to another user (items are per-user), or an id string the relay/legacy prepare function can't decode to a valid record.","commonSituations":"Two tabs open, item already deleted in the other; user sharing ids across accounts; stale cached comment library after item removal; passing global (relay) id of the wrong node type.","solutions":["Verify the id exists: CommentBankItem.active.find_by(id:) for the current user.","Refresh the comment bank list and delete only ids currently returned.","Ensure the id is the CommentBankItem's own relay/legacy id, not another node's.","Treat this error as idempotent success if the item was already deleted."],"exampleFix":"// before\ndeleteCommentBankItem(input: { id: staleId })\n// after\nconst item = user.commentBankItems.find(i => i.id === id)\nif (item) deleteCommentBankItem(input: { id: item.id })","handlingStrategy":"validation","validationCode":"const item = me.commentBankItems?.nodes?.find(i => i._id === id)\nif (!item) throw new SkipError('comment bank item missing')","typeGuard":"function itemExists(items, id) { return (items || []).some(i => String(i._id ?? i.id) === String(id)); }","tryCatchPattern":"try {\n  await deleteCommentBankItem({ id })\n} catch (e) {\n  if (e.message.includes('Unable to find CommentBankItem')) {\n    refetchCommentBank(); // already deleted or wrong id\n  } else throw e;\n}","preventionTips":["Refetch the user's comment bank before delete operations.","Handle double-delete as success (idempotent UX).","Ensure ids come from the same user's comment bank query."],"tags":["graphql","record-not-found","comment-bank"],"backgroundTag":"record-not-found","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}