mirror of
https://github.com/raidendotai/cofounder
synced 2025-02-01 23:44:30 +00:00
Fix backend code relooping issue
Related to #11 Improve error handling and retry mechanism for backend code generation process. * **Handle empty generated server code gracefully in `cofounder/api/system/functions/backend/server.js`** - Add a check to handle empty generated server code in the `backendServerGenerate` function. - Log a specific error message if the generated server code is empty. - Return an empty server code structure if the generated server code is empty. * **Update retry mechanism in `cofounder/api/build.js`** - Add a condition to stop retrying if the generated server code is empty after a certain number of attempts in the `system.run` function. - Update the retry mechanism to include the new condition in the `fn` function. - Log a specific error message if the generated server code is empty after the maximum retries. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/raidendotai/cofounder/issues/11?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
parent
3d3ee9326b
commit
fdfc0a83f0
@ -82,7 +82,7 @@ async function build({ system }) {
|
||||
return await queues[id].add(async () => {
|
||||
events.log.node.emit(`start`, { id, context, data });
|
||||
const response = await retry(
|
||||
async (bail) => {
|
||||
async (bail, attempt) => {
|
||||
try {
|
||||
const fnresponse = await system.functions[id]({
|
||||
context: { ...context, run: system.run },
|
||||
@ -94,6 +94,14 @@ async function build({ system }) {
|
||||
: data,
|
||||
});
|
||||
|
||||
if (!fnresponse || (id === 'BACKEND:SERVER::GENERATE' && !fnresponse.backend.server.main.mjs)) {
|
||||
if (attempt >= (parseInt(system.nodes[id].queue?.retry) || 5)) {
|
||||
console.error(`backend:server:generate error - generated is empty after ${attempt} attempts`);
|
||||
return { success: false };
|
||||
}
|
||||
throw new Error("backend:server:generate error - generated is empty");
|
||||
}
|
||||
|
||||
return !fnresponse
|
||||
? { success: false }
|
||||
: system.nodes[id].out?.length
|
||||
|
@ -311,7 +311,20 @@ now do the analysis , write the full working script and specify the dependencies
|
||||
|
||||
const { mjs } = extraction;
|
||||
if (!mjs.length || !extraction.yaml) {
|
||||
throw new Error("backend:server:generate error - generated is empty");
|
||||
console.error("backend:server:generate error - generated is empty");
|
||||
return {
|
||||
backend: {
|
||||
...data.backend,
|
||||
server: {
|
||||
main: {
|
||||
mjs: "",
|
||||
dependencies: {},
|
||||
env: {},
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const parsedYaml = extraction.yaml ? yaml.parse(extraction.yaml) : {};
|
||||
|
Loading…
Reference in New Issue
Block a user