public ScriptCompilationException(string scriptPath, CompilerException e) : base(e.Message, e) { _scriptPath = scriptPath; _errors = e.Data["Errors"] as List <string> ?? new List <string>(); _warnings = e.Data["Warnings"] as List <string> ?? new List <string>(); }
public void AddError(CompilerException ex) { if (null == ex.Location) { ex.Location = CurrentLocation; } if (null != ex.Location) { ex.Location.SourceFile = SourceFile; } _errors.Add(ex); SetArmState(ArmState.error); if (null != ex.Location) { Trace("{0}: {1}", ex.Location, ex.Message); } else { Trace("{0}", ex.Message); } }
private void CreateImplicitFolders(FrontendCompiler context, List <FileSystemResource> implicitPaths) { implicitPaths.Sort((x, y) => x.Path.CompareTo(y.Path)); foreach (FileSystemResource r in implicitPaths) { string path = String.Empty; Folder parentFolder = null; string[] splitPath = r.Path.Split(FileSystemResourceManager.DirectorySplitChars, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < splitPath.Length - 1; ++i) { Folder folder = null; Resource found = null; path = IO.Path.Combine(path, splitPath[i]) + "\\"; if (path.EndsWith(":\\", StringComparison.Ordinal)) { PackageItem item; if (context.TryGetItemById(path.Substring(0, path.Length - 2), out item)) { folder = (Folder)item; } } else if (this.resolvedPaths.TryGetValue(path, out found)) { folder = found as Folder; if (folder == null) { CompilerException.ThrowInternalError("Failed to resolve path to Folder. The path: '{0}' should resolve to a Folder instead of: '{1}'.", path, found); } else if (folder.ParentFolder != parentFolder) { CompilerException.ThrowInternalError("Found Folder.ParentFolder does not match expected parent Folder. Ensure path: '{0}' is correctly rooted to Folder/@Id='{1}'.", path, folder.Id); } } else // need to create the implicit folder. { folder = new Folder(); folder.Group = r.Group; folder.Name = splitPath[i]; parentFolder.Items.Add(folder); context.AddItem(r.LineNumber, folder); // Since the folder was just created, we need to jump start its "resolving" since all // of the other resources have already started resolve. folder.ResolveGroup(context); folder.BeginResolve(context); this.ResolvePath(context, folder); } parentFolder = folder; } if (r.ParentFolder != parentFolder) { r.ReparentFolder(parentFolder); } } }
internal void VerifyResolvedConsistency() { if (this.Deleted) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was deleted."); } if (this.Parent != null && this.Parent.Deleted) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Parent was deleted."); } if (this.Group != null && this.Group.Deleted) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Group was deleted."); } if (!this.resolved) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was not resolved."); } if (this.resolving) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Item was still resolving."); } if (!this.resolvedGroup) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Item did not resolve its group."); } this.OnVerifyResolvedConsistency(); }
protected override void OnVerifyResolvedConsistency() { base.OnVerifyResolvedConsistency(); if (this.ParentFolder != null && this.ParentFolder.Deleted) { CompilerException.ThrowInternalError("Internal resolved consistency violation: File system ParentFolder was deleted."); } }
public static DataphorFault ExceptionToFault(DataphorException exception) { DataphorFault fault = new DataphorFault(); fault.ExceptionClassName = exception.GetType().Name; fault.Code = exception.Code; fault.Severity = exception.Severity; fault.Message = exception.Message; fault.Details = exception.Details; fault.ServerContext = exception.ServerContext; if (exception.InnerException != null) { fault.InnerFault = ExceptionToFault(exception.InnerException); } #if !SILVERLIGHT // Under Silverlight, a ConnectionException will come back as a DataphorException // The statement is still present in the Details. ConnectionException connectionException = exception as ConnectionException; if (connectionException != null) { fault.Statement = connectionException.Statement; } #endif SyntaxException syntaxException = exception as SyntaxException; if (syntaxException != null) { fault.Locator = syntaxException.Locator; fault.Line = syntaxException.Line; fault.LinePos = syntaxException.LinePos; fault.Token = syntaxException.Token; fault.TokenType = syntaxException.TokenType; } CompilerException compilerException = exception as CompilerException; if (compilerException != null) { fault.Locator = compilerException.Locator; fault.Line = compilerException.Line; fault.LinePos = compilerException.LinePos; fault.ErrorLevel = compilerException.ErrorLevel; } RuntimeException runtimeException = exception as RuntimeException; if (runtimeException != null) { fault.Locator = runtimeException.Locator; fault.Line = runtimeException.Line; fault.LinePos = runtimeException.LinePos; fault.Context = runtimeException.Context; } return(fault); }
/// <summary> /// Format and write a <see cref="CompilerException"/> /// </summary> private async Task WriteCompilerException(CompilerException ex) { var message = Formatter switch { LogFormatter.MSBuild => $"{ReservedWords.CompilerName} : fatal error BOP{ex.ErrorCode}: {ex.Message}", LogFormatter.Structured => $"[{DateTime.Now}][Compiler][Error] {ex.Message}", LogFormatter.JSON => $@"{{""Message"": ""{ex.Message}""}}", _ => throw new ArgumentOutOfRangeException() }; await Console.Error.WriteLineAsync(message).ConfigureAwait(false); }
internal void SetPath(string path) { if (String.IsNullOrEmpty(this.Path)) { this.Path = path; } else { CompilerException.ThrowInternalError("Path was already set on the Resource. Resource.SetPath() cannot be called when the Path has already been set. Attempting to overwrite path: '{0}' with path: '{1}'", this.Path, path); } }
protected override void OnVerifyResolvedConsistency() { base.OnVerifyResolvedConsistency(); foreach (PackageItem item in this.Items) { if (item.Deleted) { CompilerException.ThrowInternalError("Internal resolved consistency violation: Item contained in Group was deleted."); } } }
public void Print(CompilerException e) { if (e.Node != null) { PrintError(e.Node.LineNumber, e.Node.LetterNumber, e.Message, GetLine(e.Node.LineNumber - 1)); } else { Console.WriteLine($"\nAn error was detected:\n{e.Message}"); } }
static void ReportCompilerError(CompilerException e) { CompilerErrorCollection errors = (CompilerErrorCollection)e.Data["Errors"]; foreach (CompilerError err in errors) { Console.WriteLine("{0}({1},{2}): {3} {4}: {5}", err.FileName, err.Line, err.Column, err.IsWarning ? "warning" : "error", err.ErrorNumber, err.ErrorText); } }
public void ShowError(Exception ex) { try { string errorText = string.Empty; string callStack = string.Empty; CompilerException cex = ex as CompilerException; if (cex != null) { foreach (CompilerError error in cex.Results.Errors) { errorText += "Error Found in " + cex.Template.Header.FullFileName + " on line " + cex.Template.TemplateLineFromErrorLine(error.Line) + Environment.NewLine + error.ErrorText + Environment.NewLine + Environment.NewLine; } } else { Exception rootCause = ex; while (rootCause.InnerException != null) { if (rootCause.Equals(ex.InnerException)) { break; } rootCause = ex.InnerException; } errorText = rootCause.Message; } this.splitContainer.Panel2Collapsed = false; this.pictureBoxError.Image = Resource.error; this.textBoxError.Text = errorText; this.textBoxError.Text += Environment.NewLine + Environment.NewLine; this.textBoxError.Text += ex.StackTrace; this.textBoxError.ScrollToCaret(); } catch (Exception exx) { this.ShowError(exx); } }
private Folder GetDefaultRoot(FrontendCompiler context) { PackageItem item; if (!context.TryGetItemById(this.defaultFolderId, out item)) { CompilerException.ThrowInternalError("Failed to locate default root folder with Id: '{0}'.", this.defaultFolderId); } Folder folder = item as Folder; if (folder == null) { CompilerException.ThrowInternalError("Unexpected default root item type. Ensure Id: '{0}' resolves to a Folder instead of a: '{1}'.", this.defaultFolderId, item); } return(folder); }
private void HandleCompilerErrors(CompilerException ex, ScriptCompilerLogger logger) { logger.Error(ex); StringBuilder sb = new StringBuilder(); sb.AppendLine(ex.Message); sb.AppendLine(); sb.AppendLine($"Text: \"{ex.Text}\""); sb.AppendLine("Line: " + ex.Line); sb.AppendLine("Column: " + ex.Column); var _ = MetroMessageBox.Show("Compilation Failed", sb.ToString(), MetroMessageBox.MessageBoxButtons.Ok); if (txtScript.TextArea.Focus()) { txtScript.TextArea.Caret.Offset = txtScript.Document.GetOffset(ex.Line, ex.Column); txtScript.ScrollToLine(ex.Line); } }
private OutputDescription CompileInputDescriptionJson(string jsonInput, CompileErrorHandling errorHandling = CompileErrorHandling.ThrowOnError, Dictionary <string, string> soliditySourceFileContent = null) { // Wrap the resolver object in a using to avoid it from being garbage collected during the // execution of the native solc compile function. using (var sourceResolver = new SourceFileResolver(_solSourceRoot, soliditySourceFileContent)) { var res = _native.Compile(jsonInput, sourceResolver.ReadFileDelegate); var output = OutputDescription.FromJsonString(res); var compilerException = CompilerException.GetCompilerExceptions(output.Errors, errorHandling); if (compilerException != null) { throw compilerException; } return(output); } }
private void ReparentFolderChildren(FrontendCompiler context, Folder deleteFolder, Folder replacementFolder) { Debug.Assert(replacementFolder != deleteFolder); if (!String.IsNullOrEmpty(deleteFolder.Path) && !deleteFolder.Path.Equals(replacementFolder.Path, StringComparison.OrdinalIgnoreCase)) { CompilerException.ThrowInternalError("Reparenting to folder with different path. That should not be possible."); } foreach (FileSystemResource child in new List <FileSystemResource>(deleteFolder.Items)) { child.ReparentFolder(replacementFolder); } Debug.Assert(deleteFolder.Items.Count == 0); if (deleteFolder.ParentFolder != null) { deleteFolder.ParentFolder.Items.Remove(deleteFolder); } context.RemoveItem(deleteFolder); }
internal void ReparentFolder(Folder newParentFolder) { // Ensure this new parent folder will not change our path if we already calculated it. if (!String.IsNullOrEmpty(this.Path) && !this.Path.StartsWith(newParentFolder.Path, StringComparison.OrdinalIgnoreCase)) { CompilerException.ThrowInternalError("Reparenting folder would change already calculated path. That is not allowed."); } // If the parent was the parent folder, update the parent to point to the replacement folder. if (this.Parent == this.ParentFolder) { this.Parent = newParentFolder; } if (this.ParentFolder != null) { this.ParentFolder.Items.Remove(this); } this.ParentFolder = newParentFolder; newParentFolder.Items.Add(this); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateException"/> class. /// </summary> /// <param name="templateName">Template that failed compilation.</param> /// <param name="err">Exception thrown by the compiler.</param> public TemplateException(string templateName, CompilerException err) : base(string.Empty, err) { _err = err; _templateName = templateName; }
public void Add(CompilerException e) { Exceptions.Add(e); }
private string ResolvePath(FrontendCompiler context, FileSystemResource r) { if (String.IsNullOrEmpty(r.Path)) { // If there is a parent folder resolve it's path. string parentPath = String.Empty; if (r.ParentFolder != null) { parentPath = ResolvePath(context, r.ParentFolder); // recurse. } string path = IO.Path.Combine(parentPath, r.ParentRelativePathFromName ?? String.Empty, r.Name ?? String.Empty); Debug.Assert((r is Folder && path.EndsWith("\\", StringComparison.Ordinal)) || (r is File && !path.EndsWith("\\", StringComparison.Ordinal))); r.SetPath(path); } // If in the process of calculating this resource's path we reparented the folder (which deletes the // resource) then don't check for a conflicting resource because this resource would lose anyway. if (!r.Deleted) { Resource conflictingResource; if (this.resolvedPaths.TryGetValue(r.Path, out conflictingResource)) { if (conflictingResource == r) { // We found ourself so don't do anything. } else if (conflictingResource is Folder && r is Folder) // folders are special because the can be implicitly created. { // If our resource has an id that makes it a better candidate for the path. if (!String.IsNullOrEmpty(r.Id)) { // The conflicting resource cannot also have an Id or the backend compiler will be all confusimicated. if (!String.IsNullOrEmpty(conflictingResource.Id)) { // TODO: change this to an error message instead of an internal compiler error. CompilerException.ThrowInternalError("Two named folders refer to the same path. That is not supported."); } this.ReparentFolderChildren(context, (Folder)conflictingResource, (Folder)r); this.resolvedPaths[r.Path] = r; // this resource now owns the path. } else // the conflicting resource either has an Id or was here first so it's a better parent. { this.ReparentFolderChildren(context, (Folder)r, (Folder)conflictingResource); } } else { // TODO: change this to an error message instead of an internal compiler error. CompilerException.ThrowInternalError("Two files or a file and a folder ended up with the same path. That is not allowed."); } } else // no one owns this path yet so take it over. { Debug.Assert(r != r.ParentFolder); this.resolvedPaths.Add(r.Path, r); } } return(r.Path); }