{"record":{"id":"b82dc07fe782aab5","repo":"siyuan-note/siyuan","slug":"marketplace-package-already-exists","errorCode":null,"errorMessage":"marketplace package already exists","messagePattern":"marketplace package already exists","errorType":"exception","errorClass":"ErrLocalBazaarPackageExists","httpStatus":null,"severity":"warning","filePath":"kernel/model/bazaar.go","lineNumber":111,"sourceCode":"\tmeta installMeta\n}\n\n// ThemeInstallOptions 描述新安装主题后需要应用的外观模式\ntype ThemeInstallOptions struct {\n\tMode   int\n\tModeOS bool\n}\n\n// LocalBazaarPackageInstallResult 描述本地集市包的识别和安装结果。\ntype LocalBazaarPackageInstallResult struct {\n\tPackageType   string `json:\"packageType\"`\n\tPackageName   string `json:\"packageName\"`\n\tMinAppVersion string `json:\"minAppVersion,omitempty\"`\n\tUpdated       bool   `json:\"updated\"`\n}\n\nvar (\n\tErrLocalBazaarPackageExists       = errors.New(\"marketplace package already exists\")\n\tErrLocalBazaarPackageIncompatible = errors.New(\"marketplace package is incompatible\")\n\tlocalBazaarInstallLock            sync.Mutex\n)\n\n// updatePackages 更新一组集市包；同类型批量更新时，安装后处理只执行一次\nfunc updatePackages(packages []*UpdatedPackage, pkgType string, successCount, failedCount *int, planned int) {\n\titems := make([]batchInstallItem, 0, len(packages))\n\tfor _, updated := range packages {\n\t\tpkg := updated.Available\n\t\tmeta, err := installBazaarPackage(pkgType, pkg.RepoURL, pkg.RepoHash, pkg.RepoRef, pkg.Name)\n\t\tif err != nil {\n\t\t\tlogging.LogErrorf(\"update %s [%s] failed: %s\", pkgType, pkg.Name, err)\n\t\t\tutil.PushErrMsg(fmt.Sprintf(Conf.language(238), pkg.Name), 5000)\n\t\t\t*failedCount++\n\t\t\tcontinue\n\t\t}\n\t\titems = append(items, batchInstallItem{name: pkg.Name, meta: meta})\n\t\t*successCount++","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/bazaar.go#L93-L129","documentation":"ErrLocalBazaarPackageExists is a sentinel returned by InstallLocalBazaarPackage when the target package already exists locally and has pending updates (result.Updated) but the caller did not request overwrite. The API layer maps it to reason \"package-exists\" in the batch-install result, so callers can detect the 'already installed, update available, confirm needed' case via errors.Is.","triggerScenarios":"Calling InstallLocalBazaarPackage for a package whose installed copy differs from the source (Updated=true) while overwrite is false; batch local installs via kernel/api/bazaar.go where an item already exists.","commonSituations":"Re-running a local install of a plugin/theme that is already installed; a UI asking the user whether to overwrite and the caller passing overwrite=false; scripted installs repeated without overwrite.","solutions":["Pass overwrite=true if the existing package should be replaced","Use errors.Is(err, model.ErrLocalBazaarPackageExists) to detect this case and prompt the user for overwrite confirmation before retrying","Uninstall the existing package first if a clean install is desired"],"exampleFix":"// before\n_, err := model.InstallLocalBazaarPackage(src, \"plugins\", false, frontend)\n// after\n_, err := model.InstallLocalBazaarPackage(src, \"plugins\", false, frontend)\nif errors.Is(err, model.ErrLocalBazaarPackageExists) {\n    _, err = model.InstallLocalBazaarPackage(src, \"plugins\", true, frontend) // user confirmed\n}","handlingStrategy":"try-catch","validationCode":"// pre-check: does the package already exist and differ?\nconst exists = await api.isPackageInstalled(pkgType, pkgName);","typeGuard":"function isPackageExists(err) { return errors.Is(err, model.ErrLocalBazaarPackageExists); }","tryCatchPattern":"_, err := model.InstallLocalBazaarPackage(src, pkgType, false, frontend)\nif errors.Is(err, model.ErrLocalBazaarPackageExists) {\n    if userConfirmsOverwrite() {\n        _, err = model.InstallLocalBazaarPackage(src, pkgType, true, frontend)\n    }\n}","preventionTips":["Check whether the package is already installed before a local install","Wire overwrite confirmation into the UI flow using the \"package-exists\" reason","Use errors.Is, not string comparison, against the sentinel"],"tags":["marketplace","duplicate","sentinel-error","install"],"backgroundTag":"file-already-exists","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}