siyuan-note/siyuan · error
invalid package type
Error message
invalid package type
What it means
Thrown by getPackageInstallPath when pkgType is not one of the five supported kinds: plugins, themes, icons, templates, widgets. The switch has no other cases, so any other string reaches the default branch. The invalid value is logged via logging.LogErrorf before the error is returned.
Source
Thrown at kernel/model/bazaar.go:74
if !isValidPackageName(packageName) {
return "", "", errors.New("invalid package name")
}
var baseDir, jsonFileName string
switch pkgType {
case "plugins":
baseDir, jsonFileName = filepath.Join(util.DataDir, "plugins"), "plugin.json"
case "themes":
baseDir, jsonFileName = util.ThemesPath, "theme.json"
case "icons":
baseDir, jsonFileName = util.IconsPath, "icon.json"
case "templates":
baseDir, jsonFileName = filepath.Join(util.DataDir, "templates"), "template.json"
case "widgets":
baseDir, jsonFileName = filepath.Join(util.DataDir, "widgets"), "widget.json"
default:
logging.LogErrorf("invalid package type: %s", pkgType)
return "", "", errors.New("invalid package type")
}
installPath := filepath.Join(baseDir, packageName)
if !gulu.File.IsSubPath(baseDir, installPath) {
return "", "", errors.New("invalid package name")
}
return installPath, jsonFileName, nil
}
// installMeta 记录安装前后的状态,供安装后处理使用
type installMeta struct {
update bool
}
// batchInstallItem 同类型批量安装时单个包的结果
type batchInstallItem struct {
name string
meta installMetaView on GitHub (pinned to 251596fc0d)
Solutions
- Use one of the exact strings: 'plugins', 'themes', 'icons', 'templates', 'widgets'.
- Centralize pkgType constants in the caller instead of string literals to avoid typos.
- Validate pkgType against the allowlist before issuing the request.
Example fix
// before
installPackage("plugin", name) // typo
// after
installPackage("plugins", name) Defensive patterns
Strategy: validation
Validate before calling
var validPkgTypes = map[string]bool{"plugins": true, "themes": true, "icons": true, "templates": true, "widgets": true}
if !validPkgTypes[pkgType] {
return fmt.Errorf("invalid package type: %q", pkgType)
} Type guard
func isValidPkgType(t string) bool {
switch t {
case "plugins", "themes", "icons", "templates", "widgets":
return true
}
return false
} Prevention
- Centralize package-type constants in a single shared map or const block.
- Validate pkgType at the API boundary before dispatching to install/path functions.
- Add a unit test that asserts the allowlist matches both switch statements.
When it happens
Trigger: Calling any install-path-dependent bazaar function (InstallBazaarPackage, InstallLocalBazaarPackage, UpdateBazaarPackage, getPackageUninstallPath, GetInstalledPackageSize) with a pkgType outside the allowed set, e.g. 'extensions', 'snippets', a typo like 'plugin', or an empty string.
Common situations: A frontend or integration hardcoding a package type that does not exist, a typo, or a plugin using a stale constant after a rename. Also triggered by malformed API requests.
Related errors
- invalid package name
- ErrLocalBazaarPackageExists
- ErrLocalBazaarPackageIncompatible
- installed package not found
- Failed to install marketplace package [%s]: %s
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/088b46869b54c755.
Report an issue: GitHub.