{"record":{"id":"3620baf7e1a84c61","repo":"nextcloud/server","slug":"failed-to-load-tags-for-file","errorCode":null,"errorMessage":"Failed to load tags for file","messagePattern":"Failed to load tags for file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/systemtags/src/services/files.ts","lineNumber":31,"sourceCode":"import { davClient } from './davClient.ts'\n\n/**\n * Fetch all tags for a given file (by id).\n *\n * @param fileId - The id of the file to fetch tags for\n */\nexport async function fetchTagsForFile(fileId: number): Promise<TagWithId[]> {\n\tconst path = '/systemtags-relations/files/' + fileId\n\ttry {\n\t\tconst { data: tags } = await davClient.getDirectoryContents(path, {\n\t\t\tdata: fetchTagsPayload,\n\t\t\tdetails: true,\n\t\t\tglob: '/systemtags-relations/files/*/*', // Filter out first empty tag\n\t\t}) as ResponseDataDetailed<Required<FileStat>[]>\n\t\treturn parseTags(tags)\n\t} catch (error) {\n\t\tlogger.error(t('systemtags', 'Failed to load tags for file'), { error })\n\t\tthrow new Error(t('systemtags', 'Failed to load tags for file'), { cause: error })\n\t}\n}\n\n/**\n * Create a tag and apply it to a given file (by id).\n * This returns the id of the newly created tag.\n *\n * @param tag The tag to create\n * @param fileId Id of the file to tag\n */\nexport async function createTagForFile(tag: Tag, fileId: number): Promise<number> {\n\tconst tagToCreate = formatTag(tag)\n\tconst tagId = await createTag(tagToCreate)\n\tconst tagToSet: ServerTagWithId = {\n\t\t...tagToCreate,\n\t\tid: tagId,\n\t}\n\tawait setTagForFile(tagToSet, fileId)","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/systemtags/src/services/files.ts#L13-L49","documentation":"Thrown by fetchTagsForFile() when the REPORT-style getDirectoryContents request against /systemtags-relations/files/{fileId} fails. The response is parsed with parseTags after filtering the leading empty entry with a glob, and any DAV failure (401/403/404/5xx, network) is wrapped into this error with the original cause attached.","triggerScenarios":"Requesting tags for a numeric fileId that does not exist (deleted file, id from a stale node), for a file the current user cannot read (403/404), with an expired session (401), or while the DAV endpoint is unreachable. Note only user-visible tags are returned; a file with only invisible tags looks like it has none.","commonSituations":"Files sidebar opened on a node whose id came from a stale listing; share token without read rights; session expired while the sidebar was open; scripts calling the helper with an arbitrary id instead of a real file id.","solutions":["Inspect (error.cause as WebDAVClientError)?.response?.status: 404 → the fileId is invalid or the file was deleted; 401 → refresh the session","Pass the id of a live file node (from the Files view context), not one captured earlier in the session","If the list is empty where tags are expected, remember invisible/system-internal tags are filtered — verify with an admin account","Check connectivity to /remote.php/dav if the cause is a network error"],"exampleFix":"// before\nconst tags = await fetchTagsForFile(fileId) // throws for deleted files\n\n// after\nlet tags: TagWithId[]\ntry {\n\ttags = await fetchTagsForFile(fileId)\n} catch (e) {\n\tif ((e.cause as WebDAVClientError)?.response?.status === 404) tags = [] // file gone — treat as untagged\n\telse throw e\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n\tconst tags = await fetchTagsForFile(fileId)\n} catch (error) {\n\tconst status = (error.cause as WebDAVClientError | undefined)?.response?.status\n\tif (status === 404) {\n\t\t// invalid/deleted fileId — show empty tag list or close the sidebar\n\t} else throw error\n}","preventionTips":["Use the fileId from the currently rendered file node, never one cached from an earlier view","Remember invisible tags are filtered out — an empty result can be correct, not an error","Refresh on 401 rather than retrying in a loop"],"tags":["systemtags","webdav","report","file-tags","typescript"],"backgroundTag":"webdav-report-failed","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}