How to clear/remove firebase Crashlytics custom keys? - crashlytics

You can associate arbitrary key/value pairs with your crash reports by FirebaseCrashlytics.getInstance().setCustomKey(key, value)
Fine.
But how can I revert those when I don't need anymore?
Consider following code:
// report 'ex_1' with "info" key
FirebaseCrashlytics.getInstance().setCustomKey("info", "abc");
FirebaseCrashlytics.getInstance().recordException(ex_1);
//Now I want to clear custom keys, so I want to report 'ex_2' without "info"
//FirebaseCrashlytics.getInstance().REMOVECustomKey("info");
FirebaseCrashlytics.getInstance().recordException(ex_2);

I don't see anything in the SDK that allows for this. They should really offer some way to clear the Custom Keys but the SDK does not allow for nullable values either.
The way I went around it was just to override the one-shot custom keys with a 0.
// Set key
FirebaseCrashlytics.getInstance().setCustomKey("key", "value")
// Clear key
FirebaseCrashlytics.getInstance().setCustomKey("key", 0)
It is not the cleanest approach but at least you know those values got reset.

Related

How do I require certain instance variables be provided at object creation?

Let's say I have a type of object in my game called oCharacter. All characters must have names, so I want to provide one when I construct the object. I can do that by using the _variables argument of instance_create_layer:
instance_create_layer(0, 0, "Instances", oCharacter, { name: "George" });
I could even make sure that I don't forget to do this by making a "constructor" function for characters and only instantiating them using that:
function character_create(_x, _y, _name) {
return instance_create_layer(_x, _y, "Instances", oCharacter, { name: _name });
}
But this approach has two problems.
The first is that I or another developer might forget about this convention and instantiate a character directly using instance_create_layer, forgetting to pass a name and setting up a runtime error further down the road.
The second (related) issue is that Feather doesn't know about this convention, so my Feather window is full of error messages about references to instance variables that aren't declared in the Create event - but I don't see how I can declare these variables in the Create event, as I'm expecting their value to be provided by the creator.
Is there some way of doing this that addresses these issues?
The first problem is just about setting rules about the code conventions within your team, if your team does not know about these conventions you want them to follow, then you should tell it them in a meeting.
For the second problem: Maybe you could create an empty/nullable variable in the Create Event? I'm afraid I'm not familiar with Feather
Personally I would do two things for this.
Create development standards for the team and put them in something like a Word document, wiki page, onenote, whatever makes the most sense for your team.
I would use a function to create the instance of the object (like you're doing there), and have some simple validation checks inside of the create event itself that will cancel it's creation (something like a guard clause) and output a debug message with a reminder.
It's not the most elegant solution but that should do the trick (assuming you haven't found something else by now haha)

How to add additional methods to autocomplete in IntelliJ

When I'm coding using IntelliJ I frequently use the auto-completion as a way of speeding up my coding, however there are certain methods that it doesn't seem to suggest. One example is Collectors.toMap - it will suggest toSet, toColletion and toList when I type .collect but never toMap which means I need to type more.
As a 1st question, can I fix this behaviour? As a more general question, can I add my own custom code to be auto completed in these types of circumstance?
One trick which helps me out every time while trying to collect the stream is having a placeholder variable with the expected type. Something like:
// just a placeholder variable with proper types, which I can remove later!
Map<String, String> tempMapVariable = someCollection.stream()
.collect(
// here it will suggest the .toMap(...)
Collectors.toMap(i -> i.getKey(), i -> getValue())
);
Set<String> tempSetVariable = someCollection.stream()
.map(SomeCollection::mapperFn)
.collect(
// here it will suggest the .toSet()
Collectors.toSet()
);

CEP rule to update fragments within a managed object

I need to be able to create an event processing rule that when you add a new device, you take a string value from one fragment (e.g.: c8y_Hardware.imei) and use that string to populate another fragment (e.g: c8y_Mobile.imei). So the new device would then have the same value in both c8y_Hardware.imei and c8y_Mobile.imei.
We have attempted setting up the appropriate CEP rules, but they are not working (they do compile and save).
insert into UpdateManagedObject
select
m.id as id,
{
"c8y_Mobile.imei", getString(m,"c8y_Hardware.imei")
} as fragments
from
ManagedObjectCreated as m
where
getString(m,"c8y_Hardware.imei") != "";
Any guidance on where we are messing up our syntax would be greatly appreciated.
It should be: m.managedObject.id as id.
Usually you would also get an error on compile but it can be that the streams also have an id so that it technically works in CEP. You should be able to check if it triggers on the debug stream and see the id that has been set.
Same applies for all other Cumulocity streams. The streams itself e.g. ManagedObjectCreated or AlarmUpdated etc. are not the objects directly. They have always a property like in this case managedObject or for AlarmUpdated it is alarm. This property is the actual payload.
The helper methods like getString are written in a way that you can pass either the payload or the full stream object so there it does not matter.

Attempt retrieval of value from VBA dictionary and raise error if key not in use?

I've used dictionaries (Whether they were called that or not) in a number of other languages, but there's always been a method that can be called with on parameter that either:
A) Returns the associated value if the parameter is in use as a key, or
B) Indicates in some way that the parameter is not used as a key
I've been forced into a position where I have to learn excel/VBA and used the collections class for all of about five minutes before the lack of an .exists method led me to look for something else. The general consensus seems to be that the scripting.Dictionary class is the VBA equivalent of associative arrays/dictionaries/hashtables in other languages.
The one thing I don't like the look of though is that the only way I can see of retrieving the value associated with a given key is to use the .items property (either explicitly, or via scripting.Dictionary("key")). But rather than doing anything to indicate the issue if key is not in use in the dictionary, it adds it.
I know I can use a if structure with .exists being the test to achieve the same functionality, and can write my own function that raises an error if the exists test fails, but it seems a lot of stuffing around to achieve what is core functionality in Python (raises KeyError), PHP (raises a Notice), Java (Maps return null - although that is not necessarily ideal in the case of HashMaps where null actually is a valid value - but it does work as an indicator for HashTables).
So is there any way of attempting to retrieve a value by key that will do something (ideally throw an error) if the key is not in use, rather than silently adding it? Google hasn't provided any answers - but maybe I'm just not phrasing the search well.
I find it inconvenient too that Dictionary adds the key when you access a non-existing key.
Just use Collection and write the missing Exist function yourself, e.g.
Function ExistsInCollection(ByVal c As Collection, ByVal key As Variant) As Boolean
On Error GoTo not_exists
c.Item key
ExistsInCollection = True
not_exists:
End Function

Getting key without iterating in YAML-cpp

Is there an easy way to get the key in a map using YAML-cpp without iterating? I see in the instructions that I can use the first() method of the YAML-cpp iterator class, but I don't need to actually iterate. I have a key that I can identify by indentation level, but what I need to do now is throw an exception if the key is not one of a known list. My code currently looks like this:
std::string key;
if (doc.FindValue("goodKey")
{
// do stuff
key = "goodKey";
} else if (doc.FindValue("alsoGoodKey") {
// do stuff
key = "alsoGoodKey";
} else throw (std::runtime_error("unrecognized key");
// made it this far, now let's continue parsing
doc[key]["otherThing"] >> otherThingVar;
// etc.
See, I need the key string to continue parsing because otherThing is under goodKey in the YAML file. This works fine, but I'd like to tell the user what the unrecognized key was. I don't know how to access it, though. I don't see any functions in the header file that give me that value. How do I get it?
There isn't necessarily a single "unrecognized key". For example, your YAML file might look like:
someKey: [blah]
someOtherKey: [blah]
or it might even be empty, e.g., {}. In the former case, which one do you want? In the latter case, there are no keys.
You're asking for how to "get the key in a map", but maps can have zero or more keys.
As a side note, you can simplify some of this using the actual result of FindValue, assuming you don't actually need the name of the key that you grabbed. For example:
const YAML::Node *pNode = doc.FindValue("goodKey");
if(!pNode)
pNode = doc.FindValue("alsoGoodKey");
if(!pNode)
throw std::runtime_error("unrecognized key");
(*pNode)["otherThing"] >> otherThingVar;
// etc