Cem
Cem
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
how can we progress from here?
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
well at least we're not missing something obvious!
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
@Hard@Work | R2 ?
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
And here is the index.ts
import { constructRouter } from './router';

export { Views } from './views';

export default {
async fetch(
request: Request,
env: Bindings,
ctx: ExecutionContext,
): Promise<Response> {
// Setup logging to datadog
const logger = new Logger(
new DatadogLoggerProvider({
apiKey: env.DD_API_KEY,
applicationKey: env.DD_APP_KEY,
environment: env.ENVIRONMENT,
}),
);

// Construct router
const app = await constructRouter(request, env, logger, ctx);

return app.fetch(request, env, ctx);
},
};
import { constructRouter } from './router';

export { Views } from './views';

export default {
async fetch(
request: Request,
env: Bindings,
ctx: ExecutionContext,
): Promise<Response> {
// Setup logging to datadog
const logger = new Logger(
new DatadogLoggerProvider({
apiKey: env.DD_API_KEY,
applicationKey: env.DD_APP_KEY,
environment: env.ENVIRONMENT,
}),
);

// Construct router
const app = await constructRouter(request, env, logger, ctx);

return app.fetch(request, env, ctx);
},
};
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
Hi @Hard@Work | R2 , it is constructed during the Hono router construction under the init() method as such:
export async function constructRouter(
request: Request,
env: Bindings,
logger: Logger,
ctx: ExecutionContext,
): Promise<Hono<{ Bindings: Bindings }>> {
const app = new Hono<{ Bindings: Bindings }>();

// Register logging middleware
app.use('*', async (event, next) => {
try {
logger.send(ctx);
await next();
} catch (error: any) {
logger.error(error);
logger.send(ctx);
return event.json(
{
message: 'Server error',
},
500,
);
}
});
// Register CORS middleware
app.use('*', async (event, next) => {
await next();
event.res.headers.set(
'Access-Control-Allow-Origin',
event.req.header('origin') ?? '*',
);
event.res.headers.set('Access-Control-Max-Age', '86400');
event.res.headers.set(
'Access-Control-Allow-Methods',
'GET, PATCH, POST, PUT, DELETE, OPTIONS, HEAD',
);
event.res.headers.set(
'Access-Control-Allow-Headers',
'origin, content-type, accept, authorization, x-requested-with, x-datadog-trace-id, x-datadog-parent-id, x-datadog-origin, x-datadog-sampling-priority, x-datadog-sampled',
);
});

// Register OPTIONS handler
app.options('*', (event) => event.text(''));

// Register User class init middleware
app.use('*', async (event, next) => {
try {
event.env.User = new User(request, env, logger) as User;
await event.env.User.init();
await next();
} catch (err) {
logger.error(err, {
user: event.env.User.info.id,
});
return event.json(
{
errors: {
status: 401,
title: 'You must be authenticated to access this resource',
},
},
401,
);
}
});
export async function constructRouter(
request: Request,
env: Bindings,
logger: Logger,
ctx: ExecutionContext,
): Promise<Hono<{ Bindings: Bindings }>> {
const app = new Hono<{ Bindings: Bindings }>();

// Register logging middleware
app.use('*', async (event, next) => {
try {
logger.send(ctx);
await next();
} catch (error: any) {
logger.error(error);
logger.send(ctx);
return event.json(
{
message: 'Server error',
},
500,
);
}
});
// Register CORS middleware
app.use('*', async (event, next) => {
await next();
event.res.headers.set(
'Access-Control-Allow-Origin',
event.req.header('origin') ?? '*',
);
event.res.headers.set('Access-Control-Max-Age', '86400');
event.res.headers.set(
'Access-Control-Allow-Methods',
'GET, PATCH, POST, PUT, DELETE, OPTIONS, HEAD',
);
event.res.headers.set(
'Access-Control-Allow-Headers',
'origin, content-type, accept, authorization, x-requested-with, x-datadog-trace-id, x-datadog-parent-id, x-datadog-origin, x-datadog-sampling-priority, x-datadog-sampled',
);
});

// Register OPTIONS handler
app.options('*', (event) => event.text(''));

// Register User class init middleware
app.use('*', async (event, next) => {
try {
event.env.User = new User(request, env, logger) as User;
await event.env.User.init();
await next();
} catch (err) {
logger.error(err, {
user: event.env.User.info.id,
});
return event.json(
{
errors: {
status: 401,
title: 'You must be authenticated to access this resource',
},
},
401,
);
}
});
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
@Hard@Work | R2 I'm not sure if this is where the error is coming from but the stack trace seems to suggest this method from our class:
async listViews(): Promise<ViewData[]> {
let views: ViewData[] = [];
try {
const viewsRaw = await this.viewer.fetch(
constructUrl(`${this.info.id}/list`),
);
views = await viewsRaw.json();
} catch (e: any) {
this.logger.error('Failed to fetch view list', e);
throw e;
}
return views;
}
async listViews(): Promise<ViewData[]> {
let views: ViewData[] = [];
try {
const viewsRaw = await this.viewer.fetch(
constructUrl(`${this.info.id}/list`),
);
views = await viewsRaw.json();
} catch (e: any) {
this.logger.error('Failed to fetch view list', e);
throw e;
}
return views;
}
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
Or what I/O operation might be throwing the error?
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
To help narrow it down, would you be able to tell me if that error comes from interacting with the durable object or not?
14 replies
CDCloudflare Developers
Created by Cem on 8/4/2024 in #workers-help
Enterprise customer - cannot perform I/O error
Hi @Hard@Work | R2 - thanks for the response. However, we're not declaring any variables at the global scope.
14 replies