I have written functions in the app script bound to a google sheet that validates sheet data and shows a pop up in the sheet when there is an error.
Now, I am calling same functions form API calls in a Node js application to return a validation response without interacting google sheet.
API calls are successful, function gets called but unable to initialize UI.
I just don't want to write duplicate functions for same purpose but without accessing UI.
I get an error that says Script error message: Exception: Cannot call SpreadsheetApp.getUi() from this context.
How do I solve this issue by retaining the UI calling functionality of the app script functions and also getting work done through API?
You can put the call in a try catch block.
try {
SpreadsheetApp.getUi();
} catch (f) {
// do nothing here
}
Related
I am currently working on a simple app to store workout routines in Nuxt 3 and Appwrite. The link to the source code is here.
After logging in and adding in some workouts in the app's UI, whenever I try to call the deleteWorkout function, I get an error in the console saying that the function is not defined, whereas I have clearly defined in the workoutStore. I can't seem to figure out the reason for the same.
The same can be seen in the given screenshot.
Console on clicking the delete button
PS:
Most probably the error should be originating from either /pages/workouts.vue, /components/WorkoutDetails.vue or /stores/workout.js.
I am using Appwrite to manage the back-end of the web app, and the instructions to setup the same can be found in the README.md. (Though I don't think the error I am facing is related to the same.)
In your code the problem is, you declear your deleteWorkout() function outside of the actions block in workout.js file.
Make sure all your functions in the workout store are inside the actions block. Then it will be accessable from the vue component
I want to have global error handling in Vue.JS, like the error handling system in Angular 2+. I have tried so much but I could not find a good approach to implement this handling.
Imagine you have many service methods and that these methods should run one after the other (I mean inside each other) so writing then and catch method inside the prevoius service is so ugly and unclean and now I'm looking for clean way to implement such way. I hope you understand what I mean.
As #Badgy mentioned you can install a Vue error handler to catch errors Vue encounters. This can be done as follows:
Vue.config.errorHandler = function (err, vm, info) {
// handle error
// `info` is a Vue-specific error info, e.g. which lifecycle hook
// the error was found in. Only available in 2.2.0+
}
The above code can be located anywhere you like in your javascript. I locate the code just before I create my vue instance. i.e before my var app = new Vue({...}); code. Because it's a global vue error handler it will handle errors from all instances of vue as well as vue components. I find that in practice it mostly catches errors that occur in the vue render methods.
You can read more about it in the official docs here: https://v2.vuejs.org/v2/api/#errorHandler
For more general (non vue related) javascript errors you still need a global error handler like so:
window.onerror = function (msg, url, line, col, error) {
//code to handle or report error goes here
}
Again, this code can be placed anywhere javascript is allowed but typically you will want to place it to run early in your javascript stack. You can read more about this here: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
And finally, to catch a "Promise rejection" (i.e. an exception throw from a Promise function) we need to listen for unhandledrejection events since a Promise rejection is not caught by the window.onerror mechanism (thanks to #Blauhirn for the tip). In some browsers (Chrome and Edge currently) Promise rejections can be caught with the following approach:
window.addEventListener('unhandledrejection', function(event) {
//handle error here
//event.promise contains the promise object
//event.reason contains the reason for the rejection
});
For more info see this StackOverflow question: Catch all unhandled javascript promise rejections
I hope i understood your Question Right, but this could be what you are Looking for.
errorCaptured
Type: (err: Error, vm: Component, info: string) => ?boolean
Details: Called when an error from any descendent component is
captured. The hook receives three arguments: the error, the component
instance that triggered the error, and a string containing information
on where the error was captured. The hook can return false to stop the
error from propagating further.
Here is more in-Depth Info About it.
Be careful its Vue 2.5.0+
I'm trying to use Objective-C Bridge in a Javascript for Automation script to access the Event Store. Here's my code:
ObjC.import('EventKit');
var store = $.EKEventStore.alloc.initWithAccessToEntityTypes($.EKEntityMaskReminder);
var predicate = store.predicateForRemindersInCalendars($.Nil);
store.fetchRemindersMatchingPredicateCompletion(predicate, function(reminders){
console.log(reminders)
});
However the script completes, presumably before the function is called- nothing appears in the log.
Is there a way to make this work, such as to make it run synchronously instead, or to make the script wait until the completion handler finishes?
I am using jasmine to test my front end, and have a spy set up to watch for the edit function to be called within a controller. The callback takes a message and either brings up the edit view or throws an error.
spyOn(edit, "edit").andCallFake (callback) ->
console.log(callback)
callback()
I also have a spy setup to watch for a function in the model that fetches an updated version of the item within the edit controller.
spyOn(ag, "fetchLatestVersion").andCallFake (callback) ->
console.log(callback)
callback()
This function returns a message that gets sent to the edit callback and then displays the view or throws an error.
My edit function is running correctly until it gets to the fetchLatestVersion() function and then it doesn't seem to want to run the callback and doesn't even seem to output what the callback is. Any help with jasmine's .andCallFake() would be much appreciated.
Thanks in advance!
EDIT:
I just removed the edit spy (ended up being unnecessary) and my error has since changed. I am receiving the correct callback function from .fetchLatestVersion(), but I end up getting an error saying:
Error: Expected a spy, but got Function.
Let me know if you need more information. Thanks again!
This turned out to be an issue with Spine (the frontend framework) and how it finds objects. It makes a clone rather than returning the actual object. By changing the records to irecords I was able to get the test to pass correctly!
I am trying to get the standard Visual Studio 2012 MVC4 Internet template and oAuth to work but it won't!
So here are the simple steps to recreate.
Create new MVC4 Inernet Application
In Package Manager console execute: update-package
Un-comment OAuthWebSecurity.RegisterGoogleClient() in file AuthConfig.cs (I was under the impression that the Google oAuth does not need a key so un-commenting this line in the AuthConfig.cs file would enable it.)
F5 to run app
at this point I see the following error:
Error when entering login page:
Unhandled exception at line 115, column 5 in http://localhost:63180/Scripts/jquery.unobtrusive-ajax.js
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'live'
Click the login link on home page
Click the Google Button
at this point I get this error:
ProtocolException was unhandled by user code
No OpenID endpoint found
The cause of the error and the solution
The cause is that jquery-unobtrusive-ajax.js who is in charge of supporting the unobtrusive ajax in ASP.NET MVC using jQuery live method. But this method was deprecated in jQuery 1.7 and has been removed in 1.9.
This method allowed an event associated with any DOM element present or future.
The method to be used in place of live currently is the method on.
However the syntax is a bit different, since the method has more uses on jQuery.
$ ("form [data-ajax = true].") live ("submit", function (e) { ... }
modify the call to live with a call to on.
For on act like we happen to live on 3 parameters:
The event (like live, will "submit")
A selector (elements "children") is based selector which must always exist
The handler function (like live).
In this case our line looks like:
$ ("body"). on ("submit", "form [data-ajax = true]", function (e) { ... }
I moved the selector to the second parameter of on and have made you a basic selector "body" (not the most optimal, but well I'm sure there always).
The idea is that the last function is associated with all current and future elements of type form [data-ajax = true] that are within the selector base (body).
For all other calls to live (there are 3 more) make the same substitution that we be as follows:
$ ("body"). on ("click", "form [data-ajax = true]: submit", function (e) { ... }
$ ("body"). on ("click", "a [data-ajax = true]", function (e) { ... }
$ ("body"). on ("click", "form [data-ajax = true] input [type = image]", function (e) { ... }
And ready! With this we have recovered ajax functionality MVC unobtrusive and your application should work properly again!
translated from: http://geeks.ms/blogs/etomas/archive/2013/01/18/jquery-1-9-y-el-unobtrusive-ajax-de-asp-net-mvc.aspx
The unobtrusive library in NuGet has not been updated and does not work with jQuery 1.9.
See Unobtrusive Ajax stopped working after update jQuery to 1.9.0