Skip to content

Commit

Permalink
Improve errors returned.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnstee committed May 7, 2024
1 parent e0207ae commit 1f74bbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion FileManager.cs
Expand Up @@ -280,7 +280,7 @@ private Handle Find(ISystemContext _context, uint fileHandle)
catch (Exception ex)
{
Log.Logger.Error(ex.Message, ex);
return StatusCodes.BadDecodingError;
return new ServiceResult(StatusCodes.BadDecodingError, ex);
}
finally
{
Expand Down
28 changes: 15 additions & 13 deletions UANodeManager.cs
Expand Up @@ -139,8 +139,7 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e
string contents = File.ReadAllText(file);
string fileName = Path.GetFileNameWithoutExtension(file);

NodeState assetNode = CreateAssetNode(fileName);
if (assetNode == null)
if (!CreateAssetNode(fileName, out NodeState assetNode))
{
throw new Exception("Asset already exists");
}
Expand Down Expand Up @@ -356,18 +355,19 @@ public override void DeleteAddressSpace()
return StatusCodes.BadInvalidArgument;
}

NodeState assetNode = CreateAssetNode(assetName);
if (assetNode == null)
bool success = CreateAssetNode(assetName, out NodeState assetNode);
if (!success)
{
return StatusCodes.BadBrowseNameDuplicated;
return new ServiceResult(StatusCodes.BadBrowseNameDuplicated, new LocalizedText(assetNode.NodeId.ToString()));
}
else
{
assetId = assetNode.NodeId;
return ServiceResult.Good;
}

assetId = assetNode.NodeId;

return ServiceResult.Good;
}

private NodeState CreateAssetNode(string assetName)
private bool CreateAssetNode(string assetName, out NodeState assetNode)
{
lock (Lock)
{
Expand All @@ -388,7 +388,8 @@ private NodeState CreateAssetNode(string assetName)
NodeStateReference node = reference as NodeStateReference;
if ((node.Target != null) && (node.Target.DisplayName.Text == assetName))
{
return null;
assetNode = node.Target;
return false;
}

reference = browser.Next();
Expand All @@ -404,7 +405,8 @@ private NodeState CreateAssetNode(string assetName)

AddPredefinedNode(SystemContext, asset);

return asset;
assetNode = asset;
return true;
}
}

Expand All @@ -424,7 +426,7 @@ private NodeState CreateAssetNode(string assetName)

_fileManagers.Remove(assetId);

DeleteNode(Server.DefaultSystemContext, assetId);
DeleteNode(SystemContext, assetId);

IEnumerable<string> WoTFiles = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "settings"), "*.jsonld");
foreach (string file in WoTFiles)
Expand Down

0 comments on commit 1f74bbe

Please sign in to comment.