I'm trying to use nodegit to get the tree of a commit based on a reference or oid using Revparse, I thought the following code would work, however I'm getting getTree undefined errors:
return git.Repository.open(path_to_repo)
.then((repo) => git.Revparse.single(repo, "other"))
.then((commit) => commit.getTree());
How do I cast the object returned by Revparse to a commit?
So RevParse.single returns an Object which really is just a low level libgit2 object. That will have to have its type checked to make sure it's an Object.TYPE.COMMIT. If it is then you can grab the OID and use that to get the actual Commit.
Since NodeGit is really just bindings to libgit2 there's isn't (currently) any way to really cast an object from 1 thing to another. You have to do the lookups yourself.
Now if you're just trying to get the commit that a given reference points to you could modify your code to this:
return git.Repository.open(path_to_repo)
.then((repo) => repo.getReferenceCommit("other"))
.then((commit) => commit.getTree());
Related
I've heard that it is bad practice to set an expected type of a variable to any.
However, I don't understand, how I can get a return type of an imported function, which returns an object, which is only used in the library.
As an example, if I would like to use the crypto.createCipheriv() function provided by Node.js, which returns a Cipher object as stated in the docs, I would not known how to give a variable this type.
const variable: ReturnType<crypto.createCipheriv>;
While multiple lot Allocation I am getting error:
Unable to cast object of type 'PX.Objects.IN.INLotSerialStatus'
to type 'PX.Objects.IN.Overrides.INDocumentRelease.LotSerialStatus'.
First unpublish all customization and try to reproduce the issue.
If it goes away re-publish customizations one by one until you find the one causing the cast error.
Review the code of the customization for all references to INLotSerialStatus and LotSerialStatus. Also look at Acumatica traces to find more details about the error.
A LotSerialStatus object is also a INLotSerialStatus because LotSerialStatus inherits from INLotSerialStatus. This is a valid assignment.
The inverse is not true, maybe there is an invalid assignment for which no cast is possible in the source code of the customization:
I am using Jest (TypeScript on Node.js) for unit testing and would like to check if a specific property is either an Array or undefined using expect.objectContaining(). This property may or may not exist in the object, hence why I want my test to include both cases.
My initial idea was to use
propertyInQuestion: expect.any(Array || undefined)
inside objectContaining(), but it fails because an Array is expected. When I checked the documentation, it stated that an expected object must be a subset of the received object, so it contains properties that are present in the expected object. So what happens when a property is either present and must be of an Array type or is undefined and therefore not present in the object?
At the moment, test looks something like this
expect(someObject).toEqual(
expect.objectContaining({
propertyInQuestion: expect.any(Array),
something: expect.any(Array),
})
);
and the property I'd like to check is propertyInQuestion, which can either be an Array or undefined.
Any sort of help is appreciated. Thank you!
I have some code that is taking any ol' object and trying to output it as JSON. The problem is that in one of these cases it insists there is a circular reference and thus fails.
According to my debugger this isn't the case (but then again, I don't know the traversal logic for this function either so I can't be sure).
What would be great is to have
JSON.stringify say "Converting circular structure to JSON 'foo.baz.bat' "
where 'foo.baz.bat' is the first offending reference.
Is there a way to do this without implementing my own custom replacer? For this particular part of the code it's job should ONLY be to format to JSON and absolutely nothing more. Meaning: I don't want to massage the data here if that's what it takes.
To be clear: What makes this different from other posts suggesting that I write a custom replacer to munge-out the data is that I just need this to debug what the offending member is.
Something already built in.
Install json-stringify-safe
And the offending field will be shown as [Circular], like this:
{
"circularRef": "[Circular]",
"list": [
"[Circular]",
"[Circular]"
]
}
I need to build a grammer containing a cross reference, which may be invalid, i.e. points to a nonexisting target. A file containing such a reference should not yield an error, but only a warning. The generator would handle this as as a special case.
How can I do this with XText?
It's not possible to create valid cross references to non-existing targets in EMF.
I would suggest to go with EAttributes instead of EReferences:
Change the feature=[EClass|ID] by feature=ID in {YourDSL} grammar.
Provide a scope calculation utility like it's done in *scope_EClass_feature(context, reference)* method in the {YourDSL}ScopeProvider class. As this scoping methods simply use the eType of the given reference the reimplementation should be straightforward.
Use this scope calculation utility in {YourDSL}ProposalProvider to propose values for the introduced EAttribute.
Optionally you can use this utility in a validation rule to add a warning/info to this EAttribute if it's not "valid".
Finally use the utility in your generator to create output based on valid target eObjects.
I also ran into this problem when creating a DSL to provide declerations of variables for a none-declerative language for a transition pahse. This method works but ask yourself if you realy want to have those nasty may-references.
You can drop the auto generated error in you UI module only. To do so, provide an ILinkingDiagnosticMessageProvider and override the function getUnresolvedProxyMessage:
class DSLLinkingDiagnosticMessageProvider extends LinkingDiagnosticMessageProvider {
override getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
if(context.context instanceof YourReference) {
// return null so the your error is left out
null
} else {
// use super implementation for others
super.getUnresolvedProxyMessage(context)
}
}
}
All linker-errors for YourReference will be missed. But be aware that there will be a dummy referenced object with all fealds null. Exspecialy the name ist lost and you can not set it due to a CyclicLinkingException. But you may create a new method that sets the name directly.
Note that the dummy object will have the type you entered in your gramma. If its abstract you can easily check witch reference is not linked.