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

Inconsistent behavior of cadl compile depending on which repo I run an emitter from #1625

Closed
tjprescott opened this issue Feb 7, 2023 · 2 comments · Fixed by #1627
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@tjprescott
Copy link
Member

Here's the PR I am looking at: https://github.com/Azure/azure-rest-api-specs-pr/pull/10411

This PR is set up to use cadl-apiview 0.3.4. If I run cadl compile on this PR from the specs repo, it completes and I get an APIView. I can confirm that something isn't rendering in APIView.

Now I need to debug, so I switch to the azure-sdk-tools repo and go to the cadl-apiview folder. Here I have the same dependency versions at the PR in question and I set up launch.json so that I can run APIView on this spec and debug into that process.

# launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Compile Scratch",
            "program": "${workspaceFolder}/node_modules/@cadl-lang/compiler/dist/core/cli/cli.js",
            "args": [
              "compile",
              "E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/client.cadl",
              "--emit=\"${workspaceFolder}\"",
            ],
            "smartStep": true,
            "sourceMaps": true,
            "skipFiles": ["<node_internals>/**/*.js"],
            "cwd": "${workspaceFolder}",
          },
    ],
}

However, when I run this, that same spec with the same dependencies no longer even compiles. Instead it throws errors and thus I cannot debug into the program.

C:\Program Files\nodejs\node.exe .\node_modules\@cadl-lang\compiler\dist\core\cli\cli.js compile E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/client.cadl --emit="E:\repos\azure-sdk-tools\tools\apiview\emitters\cadl-apiview"
Cadl compiler v0.39.0
Diagnostics were reported during compilation:
E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/routes/route.oncophenotype.cadl:15:3 - error @cadl-lang/rest/duplicate-operation: Duplicate operation "GetJob1" routed at "get /".
> 15 |   @summary("Get Onco Phenotype job details")
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 16 |   @tag("OncoPhenotype")
     | ^^^^^^^^^^^^^^^^^^^^^^^
> 17 |   @doc("Gets the status and details of the Onco Phenotype job.")
     | ^^^^^^^^^^^^^^^^^^^^^^^
> 18 |   @example("./examples/SuccessfulOncoPhenotypeResponse.json", "SuccessfulOncoPhenotypeGetAnalyzeStatus")
     | ^^^^^^^^^^^^^^^^^^^^^^^
> 19 |   GetJob1 is Azure.Core.ResourceRead<OncoPhenotypeResponse>;
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/routes/route.trialmatcher.cadl:14:3 - error @cadl-lang/rest/duplicate-operation: Duplicate operation "GetJob2" routed at "get /".
> 14 |   @summary("Get Trial Matcher job details")
     |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 15 |   @tag("TrialMatcher")
     | ^^^^^^^^^^^^^^^^^^^^^^
> 16 |   @doc("Gets the status and details of the Trial Matcher job.")
     | ^^^^^^^^^^^^^^^^^^^^^^
> 17 |   @example("./examples/SuccessfulTrialMatcherResponse.json", "SuccessfulTrialMatcherGetAnalyzeStatus")
     | ^^^^^^^^^^^^^^^^^^^^^^
> 18 |   GetJob2 is Azure.Core.ResourceRead<TrialMatcherResponse>;
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/node_modules/@azure-tools/cadl-dpg/lib/decorators.cadl:3:1 - warning @azure-tools/cadl-azure-core/casing-style: The names of Namespace types must use PascalCase
> 3 | namespace Azure.DPG;
    | ^^^^^^^^^^^^^^^^^^^^

Found 2 errors, 1 warning.
Process exited with code 1

This feels very similar to this closed issue (#1232) because it had the same symptom. Running from the spec repo behaved different than running from the azure-sdk-tools repo, but I don't know that these issues are at all related.

@tjprescott tjprescott changed the title Inconsistent behavior of cadl compile Inconsistent behavior of cadl compile depending on which repo I run an emitter from Feb 7, 2023
@nguerrera nguerrera self-assigned this Feb 7, 2023
@nguerrera nguerrera added this to the [2023] March milestone Feb 7, 2023
@nguerrera nguerrera added bug Something isn't working and removed Needs Triage labels Feb 7, 2023
@nguerrera
Copy link
Contributor

I haven't figured this out yet, somehow the rest library doesn't find the right route when run from the other location. I haven't found the usual culprit of double loading of a library or global state.

The only code that seems to be loaded twice in this configuration is the cadl compiler core. There is possibly some global state in there somewhere lurking, but I haven't found it. I found one suspicious thing on projectedNameKey not using createStateSymbol, which is surely a bug, but not the blocking one.

A workaround is to change your launch.json like this, to use the core compiler next to the spec.

# launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Compile Scratch",
-            "program": "${workspaceFolder}/node_modules/@cadl-lang/compiler/dist/core/cli/cli.js",
+            "program": "${workspaceFolder}/node_modules/@cadl-lang/compiler/cmd/cadl.js",
            "args": [
              "compile",
              "E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport/client.cadl",
              "--emit=\"${workspaceFolder}\"",
            ],
            "smartStep": true,
            "sourceMaps": true,
            "skipFiles": ["<node_internals>/**/*.js"],
-            "cwd": "${workspaceFolder}",
+            "cwd": "E:/repos/azure-rest-api-specs-pr/specification/cognitiveservices/HealthDecisionSupport",
          },
    ],
}

@nguerrera
Copy link
Contributor

In PR, but I don't like the fix, so giving this an estimate of 3 to account for estimated time remaining to settle on a good fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants