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

Diffing_Engine: Handle nulls #2469

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Diffing_Engine/Compute/DiffRevisions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public static partial class Compute
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.")]
public static Diff DiffRevisions(Revision pastRevision, Revision followingRevision, DiffingConfig diffingConfig = null)
{
if(pastRevision == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot compute the diff between revisions when the past revision is null.");
return null;
}

if(followingRevision == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot compute the diff between revisions when the following revision is null.");
return null;
}

return DiffRevisionObjects(pastRevision.Objects, followingRevision.Objects, diffingConfig);
}

Expand Down
7 changes: 7 additions & 0 deletions Diffing_Engine/Convert/TryParseObjectToGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public static partial class Convert

public static bool TryParseObjectToGuid(this object obj, out Guid guid)
{
if (obj == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot parse a null object to a GUID.");
guid = Guid.Empty;
return false;
}

guid = Guid.Empty;

// If it's a Guid, extract the Id from there.
Expand Down
18 changes: 18 additions & 0 deletions Diffing_Engine/Create/Delta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public static partial class Create
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
public static Delta Delta(Revision pastRevision, Revision currentRevision, DiffingConfig diffingConfig = null, string comment = null)
{
if(pastRevision == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot create a Delta from a null past revision.");
return null;
}

if(currentRevision == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot create a Delta from a null current revision.");
return null;
}

Diff diff = Compute.DiffRevisions(pastRevision, currentRevision, diffingConfig);

return new Delta(pastRevision.StreamId, diff, pastRevision.RevisionId, currentRevision.RevisionId, DateTime.UtcNow.Ticks, m_Author, comment);
Expand All @@ -62,6 +74,12 @@ public static Delta Delta(Revision pastRevision, Revision currentRevision, Diffi
[Input("DiffingConfig", "Sets configs such as properties to be ignored in the diffing, or enable/disable property-by-property diffing.\nBy default it takes the DiffingConfig property of the Revision. This input can be used to override it.")]
public static Delta Delta(Revision revision, DiffingConfig diffingConfig = null, string comment = null)
{
if(revision == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot create a Delta from a null revision.");
return null;
}

Diff diff = Compute.DiffRevisions(null, revision, diffingConfig);

return new Delta(revision.StreamId, diff, revision.RevisionId, new Guid(), DateTime.UtcNow.Ticks, m_Author, comment);
Expand Down
12 changes: 12 additions & 0 deletions Diffing_Engine/Create/Revision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public static partial class Create
[Input("diffConfig", "Diffing settings for this Stream Revision. Hashes of objects contained in this stream will be computed based on these configs.")]
public static Revision Revision(IEnumerable<IBHoMObject> objects, object streamId, string revisionName = null, string comment = null, DiffingConfig diffConfig = null)
{
if(objects == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot create a revision from a null collection of objects.");
return null;
}

if(streamId == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot create a revision from a null stream ID.");
return null;
}

return new Revision(Modify.PrepareForRevision(objects, diffConfig), ProcessStreamId(streamId), diffConfig, revisionName, comment);
}

Expand Down
6 changes: 6 additions & 0 deletions Diffing_Engine/Query/RevisionFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public static partial class Query
{
public static RevisionFragment RevisionFragment(this IBHoMObject obj)
{
if(obj == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the revision fragment from a null object.");
return null;
}

return obj.FindFragment<RevisionFragment>();
}
}
Expand Down