gRPC - Import "google/api/annotations.proto" was not found or had errors - grpc

After running protoc command I'm getting below error.
google/protobuf/descriptor.proto: File not found.
google/api/annotations.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
google/api/annotations.proto:28:8: "google.protobuf.MethodOptions" is not defined.
currency.proto: Import "google/api/annotations.proto" was not found or had errors.
My protoc version is - libprotoc 3.0.0
Here is my proto file code..
syntax = "proto3";
import "google/api/annotations.proto";
service Currency {
// GetRate returns the exchange rate for the two provided currency codes
rpc GetRate(RateRequest) returns (RateResponse) {
option (google.api.http) = {
post: "/v1/convert",
body:"*"
};
};
}
....
....
My directory structure is..
I'm running below command -
protoc -I proto/ proto/*.proto --go_out=plugins=grpc:pb
It works fine if I remove the import of google/api/annotations.proto and option... but when I import the google/api/annotations.proto and compile it using protoc, it gives me error.

annotations.proto is defined in google/api in Google's Google APIs repo.
You'll need to clone that repo/folder and then add it to the --proto_path to protoc compile the proto:
git clone git#github.com:googleapis/googleapis.git
protoc \
--proto_path=proto/ \
--proto_path=googleapis \
--go_out=plugins=grpc:pb \
proto/*.proto

Related

Use WebAssembly module compiled with Emscripten in Next JS

I am trying to build a Next JS project with an imported WebAssembly module compiled using Emscripten.
The problem seems to be related to the WebPack loader being unable to import the .wasm module via the generated .js.
I would greatly appreciate some help.
My C++ file hello.cpp:
#include <math.h>
extern "C" {
int int_sqrt(int x) {
return sqrt(x);
}
}
I compile using:
em++ hello.cpp -o "../v2/lib/wasm/test.js" -s MODULARIZE -s WASM=1 -s EXPORT_NAME="SZU" -s ENVIRONMENT="web" -s EXPORTED_FUNCTIONS=_int_sqrt -s EXPORTED_RUNTIME_METHODS=ccall,cwrap
I try to use the module in one of the components like so:
import SZU from "../../../../../../wasm/test";
var int_sqrt = SZU().cwrap("int_sqrt", 'number', ['number'])
When I run npx next build the build fails with:
Error: not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)
I expect to be able to build the project using npx next build then start the server with npx next start and be able to interact with functions exported in the .wasm/.js module files generated by Emscripten.
With the help of #lab I realized my approach was wrong. This is the way I made my WASM module work:
This is my hello.cpp file. Important notice the extern "C" {} block:
#include <math.h>
extern "C" {
int int_sqrt(int x) {
return sqrt(x);
}
}
I compile using em++ the destination is the public folder in next. We need to serve the .wasm and .js statically like #lab pointed out:
em++ hello.cpp -o "../v2/public/wasm/test.js" -s MODULARIZE -s WASM=1 -s EXPORT_NAME="SZU" -s ENVIRONMENT="web" -s EXPORTED_FUNCTIONS=_int_sqrt -s EXPORTED_RUNTIME_METHODS=ccall,cwrap
I load the Emscripten generated js file using the next/script tag like so:
<Script src="/wasm/test.js" strategy='beforeInteractive'/>
In the Component I want to use my WASM module I load it inside the next/useEffect hook, wrap it with Emscripten cwrap and store the function in a reference object using next/useRef like so:
useEffect(() => {
if(typeof (window as any).SZU === 'function' && WASM.current === null){
console.log("loading WASM!");
(window as any).SZU()
.then((wasm: WASM) => {
console.log("got WASM!");
WASM.current = wasm;
int_sqrt.current = WASM.current.cwrap("int_sqrt", "number", ["number"]);
});
}
}, []);
I can call the function later like so:
console.log(`Square root of 16 is ${int_sqrt.current(16)}`);
I hope this helps someone who had the same problem.
The case for wasm is that it will compile into 2 files: a js file and a wasm file. The wasm file cannot be bundled into your app. You must serve it as a static asset (since it's basically binary code), and configure your path to align with your desired import.
Also you might want to ensure it work first. Try writing a nodejs script that import it and give it a test run. OR you can try import it into a nextjs API route, and invoke it via fetch from client-side and see if your compiled wasm work.

How do you get Deno to use the DENO_AUTH_TOKENS environment variable?

Using the DENO_AUTH_TOKENS environment variable doesn't appear to work for me. I've created a personal access token from GitHub and added it to my environment as described in the private modules page of the Deno manual. However, I still just get a 404 error:
error: Import 'https://raw.githubusercontent.com/MYCOMPANY/MYREPO/main/MYFILE.ts' failed: 404 Not Found
I've verified that the token is in the environment variable, and it succeeds in curl by executing the following:
curl -s https://$DENO_AUTH_TOKENS/MYCOMPANY/MYREPO/main/MYFILE.ts
Am I doing the import differently than the Deno runtime expects it?
import { foo } from 'https://raw.githubusercontent.com/MYCOMPANY/MYREPO/main/MYFILE.ts';
Running the script with -L debug gives a lot of verbose logging, but nothing about tokens at all.
What does it want me to do?
$ deno --version
deno 1.14.2 (release, x86_64-apple-darwin)
v8 9.4.146.16
typescript 4.4.2
This was a dumb mistake. When I added the variable to my .profile file, I forgot to add export before. It works after adding that:
export DENO_AUTH_TOKENS=aaaaaaaaaaaaaaaaaa#raw.githubusercontent.com

Why does deno's exec package execute commands without outputting messages to the terminal?

import { exec } from "https://deno.land/x/exec/mod.ts";
await exec(`git clone https://github.com/vuejs/vue.git`)
when i use git clone https://github.com/vuejs/vue.git in .sh file, It has message in terminal,
but don't have in deno
First, I think it is important to echo what jsejcksn commented:
The exec module is not related to Deno. All modules at https://deno.land/x/... are third-party code. For working with your shell, see Creating a subprocess in the manual.
Deno's way of doing this without a 3rd party library is to use Deno.run.
With that said, if you take a look at exec's README you'll find documentation for what you're looking for under Capture the output of an external command:
Sometimes you need to capture the output of a command. For example, I do this to get git log checksums:
import { exec } from "https://deno.land/x/exec/mod.ts";
let response = await exec('git log -1 --format=%H', {output: OutputMode.Capture});
If you look at exec's code you'll find it uses Deno.run under the hoods. If you like exec you can use it but you might find you like using Deno.run directly instead.

error using moment.js with serverless-bundle

how can I add moment.js locale file to serverless bundle?
Thanks for any help :)
I tried the following:
git clone git#github.com:AnomalyInnovations/serverless-nodejs-starter.git
cd serverless-nodejs-starter
npm i moment
then in file handler.js add
import moment from "moment";
and update hello with just call to moment(); (to avoid lint error)
when running local run:
serverless invoke local --function hello
the error received:
Error: Cannot find module './locale'
There seems to be an issue with the latest version of momentjs as you can see in this Github Issue. You can try the following:
npm install --save moment#2.24.0
Add a resolutions block in your package.json file as such:
"resolutions": {
"moment": "2.24.0"
}

WebConsoleListener IllegalAccessError in JavaFX 12

I recently downloaded the latest JavaFX SDK 12 and I wish to intercept Console Messages in my JavaFX WebView.
So, I have this
WebConsoleListener.setDefaultListener((webView, message, lineNumber, sourceId) -> {
//////// I am listening for a specific console message here in my
///webview
});
but I keep getting
Caused by: java.lang.IllegalAccessError: class rumbler.launcher.ApplicationLoader (in unnamed module #0x5c4c6905) cannot access class com.sun.javafx.webkit.WebConsoleListener (in module javafx.web) because module javafx.web does not export com.sun.javafx.webkit to unnamed module #0x5c4c6905
Here is my build.gradle file
javafx {
version = "12.0.1"
modules = ['javafx.base', 'javafx.controls', 'javafx.web']
}
Here are my VM OPTIONS
--module-path "path_to_\javafx-sdk-11.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.web,javafx.base
.Am I missing something?
You are using private API, which is not advised.
Anyway, the error message is quite clear:
module javafx.web does not export com.sun.javafx.webkit to unnamed module #0x5c4c6905
Whenever you want to access some non-exposed package from your project (either modular on non-modular), you need to use --add-exports:
The command line option --add-exports $module/$package=$readingmodule exports $package of $module to $readingmodule. Code in $readingmodule can hence access all public types in $package but other modules can not. [source].
So in this case, the solution is straight forward:
--add-exports javafx.web/com.sun.javafx.webkit=ALL-UNNAMED \
--module-path "path_to_\javafx-sdk-11.0.2\lib" \
--add-modules javafx.web,javafx.fxml

Resources