Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS : Generate error with 'PATCH' #1711

Open
portedison opened this issue Jan 16, 2025 · 4 comments
Open

TS : Generate error with 'PATCH' #1711

portedison opened this issue Jan 16, 2025 · 4 comments

Comments

@portedison
Copy link

I'm getting the following error -

error: 
Internal compiler error [E0001]

An unhandled panic occurred in the Encore compiler: runtime error: invalid memory address or nil
pointer dereference

This is a bug in Encore and should not have occurred. Please report this issue to the Encore team
either on Github at https://github.com/encoredev/encore/issues/new and include this error.

╭─[Stack Trace]
├─▶ clientgen.Client.func1                encr.dev/internal/clientgen/client.go:65
├─▶ clientgen.(*typescript).handleBailout encr.dev/internal/clientgen/typescript.go:1534
├─▶ clientgen.(*typescript).isRecursive   encr.dev/internal/clientgen/typescript.go:1624
├─▶ clientgen.(*typescript).writeTyp      encr.dev/internal/clientgen/typescript.go:1492
├─▶ clientgen.(*typescript).writeService  encr.dev/internal/clientgen/typescript.go:256
├─▶ clientgen.(*typescript).Generate      encr.dev/internal/clientgen/typescript.go:96
╰─[... remaining frames omitted ...]


Error executing adminApiCommand: Command failed: encore gen client --services=adminApi --output=../../packages/client-encore-admin/generated/client.ts --env=local

This occurs from the example project code (https://github.com/encoredev/examples/blob/main/ts/prisma/users/user.controller.ts#L84) -

export const update = api(
  { expose: true, method: "PATCH", path: "/users/:id" },
  async ({
    id,
    data,
  }: {
    id: number;
    data: UpdateUserDto;
  }): Promise<UserResponse> => {
    try {
      const result = await UserService.update(id, data);
      return result;
    } catch (error) {
      throw APIError.aborted(error?.toString() || "Error updating user");
    }
  },
);

All other endpoints in that file generate without an issue.

@portedison
Copy link
Author

Possible that this is a typescript/node issue -

Swapping out with -

id: number;
data: {
  name?: string;
  surname?: string;
};

rather than

id: number;
data: UpdateUserDto;

Seems to "fix" the issue.

@portedison
Copy link
Author

I've changed this to -

async ({ id, ...data }: { id: number } & UpdateUserDto): Promise<UserResponse> => {

And now it compiles correctly.

This is potentially a change in versions? I'm using "encore.dev": "^1.45.6" while the example is using "encore.dev": "^1.39.5"

🫤 I'm still a little confused why it doesn't like the data: UpdateUserDto;

@portedison
Copy link
Author

Yeah seems to not recognise the type/interface from children, this test also fails -

type Other = {
  id: number;
}

async ({
    id,
    ...data
  }: { id: number; other: Other } & UpdateUserDto): Promise<UserResponse> => {...

@fredr
Copy link
Member

fredr commented Jan 16, 2025

I tried it with the latest version of encore (1.45.7), checked out the prisma example, and it generated without problems. Have you made any changes to the example code?

What is the exact command that you run when you encounter this problem in the example?

If you cant reproduce it with the example, could you share some code so that I can try to reproduce it. Specifically the type definitions would be interesting to see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants