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

[Bug]: When main.tsp only contain minimal import, emitter fails #5419

Open
4 tasks done
allenjzhang opened this issue Dec 20, 2024 · 11 comments
Open
4 tasks done

[Bug]: When main.tsp only contain minimal import, emitter fails #5419

allenjzhang opened this issue Dec 20, 2024 · 11 comments
Assignees
Labels
bug Something isn't working spector Issues related to spector and the spec sets

Comments

@allenjzhang
Copy link
Member

Describe the bug

Right after tsp init with empty project that only, npx tsp compile . fails.

Emitter "@typespec/http-client-csharp" crashed! This is a bug.
Please file an issue at https://github.com/Microsoft/typespec/issues

Error: Root client not found
    at getRootApiVersions (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/http-client-csharp/dist/emitter/lib/client-model-builder.js:130:15)
    at createModel (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/http-client-csharp/dist/emitter/lib/client-model-builder.js:23:11)
    at Object.$onEmit [as emitFunction] (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/http-client-csharp/dist/emitter/emitter.js:44:22)
    at async runEmitter (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/compiler/dist/src/core/program.js:366:13)
    at async compile (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/compiler/dist/src/core/program.js:123:9)
    at async compileOnce (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/compiler/dist/src/core/cli/actions/compile/compile.js:36:25)
    at async compileAction (file:///C:/github/typespec-e2e-demo/sandbox/junk/node_modules/@typespec/compiler/dist/src/core/cli/actions/compile/compile.js:19:9)

main.tsp only contains following:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";

Reproduction

In E2E repo,

cd sandbox
md [project] && cd [project]
npx tsp init ../../tsptemplate.json
npm install
npx tsp compile .

Checklist

@allenjzhang allenjzhang added bug Something isn't working emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp labels Dec 20, 2024
@ArthurMa1978
Copy link
Member

We should verify if this issue exists in other languages too.

@rs-jayanth
Copy link

http-client-java compiles, but csharp and python client doesn't. There's an open issue - 5363

@msyyc
Copy link
Contributor

msyyc commented Dec 26, 2024

For python, it was already fixed by #5200 so please try latest https://www.npmjs.com/package/@typespec/http-client-python.

@m-nash
Copy link
Member

m-nash commented Jan 13, 2025

@allenjzhang what is the desired outcome here? A csproj with no cs files?

We should evaluate the assumptions we make and have cadl ranch tests for each of those.

  • Is it valid to generate an sdk with no clients?
  • Is it valid to generate an sdk with no models?
  • Is it valid to generate an sdk with no operations?
  • Is it valid to generate an sdk with none of those?
  • etc

@allenjzhang
Copy link
Member Author

The call stack is the one I would like to remove. It looked like an uncaught exception.

I tried with latest build, the result looks fine to me now with one line error:

Cannot generate CSharp SDK since no public root client is defined in typeSpec file.

BTW, nit, typespec should be TypeSpec. Once that fixed, you can close this issue. Thx

@JoshLove-msft
Copy link
Contributor

Cannot generate CSharp SDK since no public root client is defined in typeSpec file.

Probably should be "C# library" and "TypeSpec". We should follow up to find out what PR actually fixed this as it still should have been part of our triage process.

@JoshLove-msft JoshLove-msft self-assigned this Jan 15, 2025
@JoshLove-msft
Copy link
Contributor

This was fixed in #5475

@m-nash
Copy link
Member

m-nash commented Jan 16, 2025

I don't know if this was fixed would like to confirm with @allenjzhang what the expected result of an emitter should be if there are no clients or models in the spec? Should we throw an error or should we generate an empty library?

@srnagar , @joheredi , @lmazuel how are your languages handling this?

@m-nash m-nash reopened this Jan 16, 2025
@JoshLove-msft
Copy link
Contributor

JoshLove-msft commented Jan 21, 2025

As a general rule, we should not be throwing for "known" error cases. These should instead use error diagnostics. The only time we throw is for "unknown" cases. We should file an issue to scan the emitter to make sure we are following this rule.

@JoshLove-msft
Copy link
Contributor

BTW, nit, typespec should be TypeSpec. Once that fixed, you can close this issue. Thx

We should fix the casing. But we need to have a Spector test that provides an empty TypeSpec and what the expectation is for this case. Right now, languages are doing different things.

@JoshLove-msft JoshLove-msft added the spector Issues related to spector and the spec sets label Mar 4, 2025
@JoshLove-msft
Copy link
Contributor

Adding Spector label since we need a spector scenario for an empty Typespec along with the expectations.

@JoshLove-msft JoshLove-msft removed the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working spector Issues related to spector and the spec sets
Projects
None yet
Development

No branches or pull requests

6 participants