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

GenerateCode needs better checking for valid identifiers #111

Closed
jvert opened this issue May 6, 2020 · 0 comments · Fixed by #112
Closed

GenerateCode needs better checking for valid identifiers #111

jvert opened this issue May 6, 2020 · 0 comments · Fixed by #112

Comments

@jvert
Copy link
Contributor

jvert commented May 6, 2020

The problem

My home-assistant installation has some switches with entity ids like "switch.25388007840d8e5f2760_1" This causes an exception in CodeGenerator:GenerateCode() as it tries to create a property declaration like

public IEntity 25388007840d8e5f27602 => _app.Entity(\"switch.25388007840d8e5f2760_2\");

and that is not a valid C# identifier. There is some code that attempts to detect this with long.TryParse(name, out _) but that is not sufficient to handle all invalid c# identifiers.

Environment

  • NetDaemon release with the issue: 0.5.1
  • Last working NetDaemon release (if known):
  • Operating environment (Home assistant Add-on/Docker/Dev setup): docker and dev
  • Link to integration documentation on our website:

Link to or paste code that causes the issue

Traceback/Error logs

System.Linq.dll!System.Linq.Enumerable.SelectListIterator<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax, Microsoft.CodeAnalysis.GreenNode>.ToArray() (Unknown Source:0)
System.Linq.dll!System.Linq.Enumerable.ToArray<Microsoft.CodeAnalysis.GreenNode>(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.GreenNode> source) (Unknown Source:0)
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.GreenNode.CreateList(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.GreenNode> nodes, bool alwaysCreateListNode) (Unknown Source:0)
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>.CreateList(Microsoft.CodeAnalysis.GreenNode creator, System.Collections.Generic.List<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax> items) (Unknown Source:0)
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>.InsertRange(int index, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax> nodes) (Unknown Source:0)
Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.SyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>.AddRange(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax> nodes) (Unknown Source:0)
Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.AddMembers(Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax[] items) (Unknown Source:0)
DaemonRunner.dll!JoySoftware.HomeAssistant.NetDaemon.DaemonRunner.Service.App.CodeGenerator.GenerateCode(string nameSpace, System.Collections.Generic.IEnumerable<string> entities) Line 95 (\workspaces\netdaemon\src\DaemonRunner\DaemonRunner\Service\App\CodeGenerator.cs:95)
DaemonRunner.dll!JoySoftware.HomeAssistant.NetDaemon.DaemonRunner.Service.RunnerService.ExecuteAsync(System.Threading.CancellationToken stoppingToken) Line 189 (\workspaces\netdaemon\src\DaemonRunner\DaemonRunner\Service\RunnerService.cs:189)
[Resuming Async Method] (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<System.__Canon>.ExecutionContextCallback(object s) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<JoySoftware.HomeAssistant.NetDaemon.DaemonRunner.Service.RunnerService.<ExecuteAsync>d__6>.MoveNext(System.Threading.Thread threadPoolThread) (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<System.__Canon>.MoveNext() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.VoidTaskResult>.TrySetResult(System.Threading.Tasks.VoidTaskResult result) (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.SetResult() (Unknown Source:0)
[Completed] DaemonRunner.dll!JoySoftware.HomeAssistant.NetDaemon.DaemonRunner.Service.RunnerService.WaitForDaemonToConnect(JoySoftware.HomeAssistant.NetDaemon.Daemon.NetDaemonHost daemonHost, System.Threading.CancellationToken stoppingToken) Line 256 (\workspaces\netdaemon\src\DaemonRunner\DaemonRunner\Service\RunnerService.cs:256)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<System.__Canon>.ExecutionContextCallback(object s) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<JoySoftware.HomeAssistant.NetDaemon.DaemonRunner.Service.RunnerService.<WaitForDaemonToConnect>d__7>.MoveNext(System.Threading.Thread threadPoolThread) (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<System.__Canon>.MoveNext() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Runtime.CompilerServices.IAsyncStateMachineBox box, bool allowInlining) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetResult() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.DelayPromise.CompleteTimedOut() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.DelayPromise..ctor.AnonymousMethod__1_0(object state) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.TimerQueueTimer.CallCallback(bool isThreadPool) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.TimerQueueTimer.Fire(bool isThreadPool) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.TimerQueue.FireNextTimers() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.TimerQueue.AppDomainTimerCallback(int id) (Unknown Source:0)
[Native to Managed Transition] (Unknown Source:0)

Additional information

jvert added a commit to jvert/netdaemon that referenced this issue May 6, 2020
helto4real pushed a commit that referenced this issue May 6, 2020
fixes net-daemon/netdaemon #111

Co-authored-by: John Vert <john@groopit.co>
Ikcelaks pushed a commit to Ikcelaks/netdaemon that referenced this issue Dec 23, 2022
fixes net-daemon/netdaemon net-daemon#111

Co-authored-by: John Vert <john@groopit.co>
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

Successfully merging a pull request may close this issue.

1 participant