{"record":{"id":"a24ec03e408e1f39","repo":"YMFE/yapi","slug":"yapi-webconfig-adminaccount-er","errorCode":null,"errorMessage":"初始化管理员账号 \"${yapi.WEBCONFIG.adminAccount}\" 失败, ${err.message}","messagePattern":"初始化管理员账号 \"(.+?)\" 失败, (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/install.js","lineNumber":146,"sourceCode":"\n      let followCol = mongoose.connection.db.collection('follow');\n      followCol.createIndex({\n        uid: 1\n      });\n      followCol.createIndex({\n        project_id: 1\n      });\n\n      result.then(\n        function() {\n          fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'));\n          console.log(\n            `初始化管理员账号成功,账号名：\"${yapi.WEBCONFIG.adminAccount}\"，密码：\"ymfe.org\"`\n          ); // eslint-disable-line\n          process.exit(0);\n        },\n        function(err) {\n          throw new Error(`初始化管理员账号 \"${yapi.WEBCONFIG.adminAccount}\" 失败, ${err.message}`); // eslint-disable-line\n        }\n      );\n    })\n    .catch(function(err) {\n      throw new Error(err.message);\n    });\n}\n\ninstall();\n","sourceCodeStart":128,"sourceCodeEnd":156,"githubUrl":"https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/install.js#L128-L156","documentation":"During installation, setupSql tries to create the initial admin account (account name from yapi.WEBCONFIG.adminAccount) and throws this error in the rejection handler when the user-creation promise fails. The inner err.message reveals the actual DB/validation failure.","triggerScenarios":"install() -> setupSql(): the mongoose save/create of the admin user rejects — e.g. DB connection issue, duplicate admin account, schema validation failure on the user model.","commonSituations":"MongoDB not running or unreachable at install time, invalid adminAccount in config.json (empty/not an email-like value), admin account already exists from a prior partial install.","solutions":["Check err.message appended to the error for the root cause (connection refused, duplicate key, validation).","Ensure MongoDB is running and db connection settings in config.json are correct.","Set a valid adminAccount in config.json (non-empty email format).","If the admin already exists, skip re-install or remove the existing user/collection first."],"exampleFix":"// before (config.json)\n\"adminAccount\": \"\"\n// after\n\"adminAccount\": \"admin@yapi.local\"","handlingStrategy":"validation","validationCode":"if (!config.adminAccount) throw new Error('adminAccount required in config.json');\n// and verify DB reachable before install:\nawait dbModule.connect();","typeGuard":null,"tryCatchPattern":"try {\n  await setupSql();\n} catch (e) {\n  if (e.message.includes('初始化管理员账号')) {\n    console.error('Admin seeding failed:', e.message); // inspect inner err.message\n  } else { throw e; }\n}","preventionTips":["Ensure MongoDB is up and reachable before running the installer.","Set a valid, non-empty adminAccount (email format) in config.json.","Run install only once per environment."],"tags":["installation","database","admin-account"],"backgroundTag":"db-write-failed","analyzedSha":"59bade3a8a43e7db077d38a4b0c7c584f30ddf8c","analyzedAt":"2026-08-29T08:45:22.203Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}