Skip to content

Commit

Permalink
chore: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Jan 6, 2025
2 parents 81c706c + f507eb1 commit f56e5e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
19 changes: 7 additions & 12 deletions src/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ async function createStructuredMetadataWithMessage(context: Context, message: Lo
stack: message.stack,
};
callingFnName = message.stack?.split("\n")[2]?.match(/at (\S+)/)?.[1] ?? "anonymous";
logMessage = context.logger.error(message.message).logMessage;
} else if (message.metadata) {
metadata = {
message: message.metadata.message,
stack: message.metadata.stack || message.metadata.error?.stack,
caller: message.metadata.caller || message.metadata.error?.stack?.split("\n")[2]?.match(/at (\S+)/)?.[1],
};
logMessage = message.logMessage;
metadata = message.metadata;

if (metadata.stack || metadata.error) {
metadata.stack = metadata.stack || metadata.error?.stack;
metadata.caller = metadata.caller || metadata.error?.stack?.split("\n")[2]?.match(/at (\S+)/)?.[1];
}
callingFnName = metadata.caller;
} else {
metadata = { ...message };
Expand All @@ -100,7 +100,7 @@ async function createStructuredMetadataWithMessage(context: Context, message: Lo
const runUrl = PluginRuntimeInfo.getInstance().runUrl;
const version = await PluginRuntimeInfo.getInstance().version;

const ubiquityMetadataHeader = `<!-- ${HEADER_NAME} - @${instigatorName} - ${runUrl} - ${callingFnName} - ${version}`;
const ubiquityMetadataHeader = `<!-- ${HEADER_NAME} - ${runUrl} - ${callingFnName} - ${version} - @${instigatorName}`;

let metadataSerialized: string;
const metadataSerializedVisible = ["```json", jsonPretty, "```"].join("\n");
Expand All @@ -114,11 +114,6 @@ async function createStructuredMetadataWithMessage(context: Context, message: Lo
metadataSerialized = metadataSerializedHidden;
}

if (message instanceof Error) {
const content = context.logger.error(message.message).logMessage;
return `${options.raw ? content.raw : content.diff}\n\n${metadataSerialized}\n`;
}

// Add carriage returns to avoid any formatting issue
return `${options.raw ? logMessage?.raw : logMessage?.diff}\n\n${metadataSerialized}\n`;
}
2 changes: 1 addition & 1 deletion src/helpers/runtime-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CfRuntimeInfo extends PluginRuntimeInfo {
}
public get runUrl(): string {
const accountId = this._env.CLOUDFLARE_ACCOUNT_ID ?? "<missing-cloudflare-account-id>";
const workerName = this._env.CLOUFLARE_WORKER_NAME;
const workerName = this._env.CLOUDFLARE_WORKER_NAME;
const toTime = Date.now() + 60000;
const fromTime = Date.now() - 60000;
const timeParam = encodeURIComponent(`{"type":"absolute","to":${toTime},"from":${fromTime}}`);
Expand Down
15 changes: 3 additions & 12 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,8 @@ export function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unkno
env = ctx.env as TEnv;
}

const workerUrl = new URL(inputs.ref).origin;
let workerName;

if (workerUrl.includes("localhost")) {
workerName = "localhost";
} else {
workerName = `${workerUrl.split("//")[1].split(".")[0]}`;
}
PluginRuntimeInfo.getInstance({ ...env, CLOUFLARE_WORKER_NAME: workerName });
const workerName = new URL(inputs.ref).hostname.split(".")[0];
PluginRuntimeInfo.getInstance({ ...env, CLOUDFLARE_WORKER_NAME: workerName });

let command: TCommand | null = null;
if (inputs.command && pluginOptions.commandSchema) {
Expand Down Expand Up @@ -119,9 +112,7 @@ export function createPlugin<TConfig = unknown, TEnv = unknown, TCommand = unkno
console.error(error);

let loggerError: LogReturn | Error | null;
if (error instanceof Error) {
loggerError = error;
} else if (error instanceof LogReturn) {
if (error instanceof Error || error instanceof LogReturn) {
loggerError = error;
} else {
loggerError = context.logger.error(`Error: ${error}`);
Expand Down
2 changes: 1 addition & 1 deletion tests/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("SDK worker tests", () => {
! test error
\`\`\`
<!-- UbiquityOS - @gentlementlegen - http://localhost - handler - 1234
<!-- UbiquityOS - http://localhost - handler - 1234 - @gentlementlegen
{
"caller": "handler"
}
Expand Down

0 comments on commit f56e5e4

Please sign in to comment.