Linter Issue with Go-MongoDB Collections Find Query - mongodb

My Go code has several statements of the sort:
cursor, err := collection.Find(context.TODO(), bson.D{{}})
and they work as expected but the linter complains when executing:
golangci-lint run ./... && ginkgo -r -cover
The linter displays the following error:
missing type in composite literal (typecheck)
cursor, err := collection.Find(context.TODO(), bson.D{{}})
Even when I provide key/value pairs the linter still complains. How can I solve this? Thanks.

This happens when the go compiler doesn't recognize the bson.D type. Check if you have initialized go modules.
go mod init
Either ways, do a tidy
go mod tidy
If should print the following output
go: finding module for package gopkg.in/mgo.v2/bson
go: finding module for package go.mongodb.org/mongo-driver/mongo
go: finding module for package go.mongodb.org/mongo-driver/mongo/options
...
Run the linter.

Related

how to open new instance of acrobat

I'm using windows 10 task view and need to open different instances of excel word and acrobat.
I can't seem to get acrobat working. I get error: 0x800401F3 - Invalid class string on the AcroApp := ComObjCreate("AcroExch.App") line.
Any suggestions?
^+n::
oWord := ComObjCreate("Word.Application")
oWord.Documents.Add
oWord.Visible := 1
oWord.Activate
xlApp := ComObjCreate("Excel.Application")
xlApp.Visible := true
xlApp.Workbooks.Add()
xlApp := ""
run notepad
run chrome
AcroApp := ComObjCreate("AcroExch.App"); Error when running
AcroApp.Visible := true
AcroApp.Open
return
While the COM approach seems cool, it seems really unnecessary.
I don't have Acrobat, but a quick Google search tells me they have a command line option to open a new instance, as I suspected (documented here).
So, a quick little run command should do the trick:
Run, % """C:\Path\To\Acrobat.exe"" /n"
Also, maybe this is why your COM approach didn't work?

Compiling multiple Coq files does not work

I'm really lost on how to actually use multiple files in Coq. I was trying to follow these directions.
I have two files.
src/a.v:
Definition bar: nat := 1.
src/b.v:
Require Import a.
Definition foo := bar.
I attempt to compile as such:
coqc -R src "" src/a.v src/b.v
I get the following error:
user#machine:~/code/coq$ coqc -R src "" src/a.v src/b.v
While loading initial state:
Loading file /home/user/code/coq/src/.b.aux: aux file name mismatch
I can't find any clear information on how you actually compile with multiple files
I recommend you perform two calls to coqc, first with a then with b. Having multiple files in the argument command line is actually not supported [we will improve the interface in next versions as to warn about this]

Command StdinPipe closes too soon

I've been trying to call pg_restore using exec.Command and feed StdinPipe with data from database dump file, it works with small files under 1Mb but it fails for bigger dumps with the write |1: broken pipe error. I also tried to scan line by line and write to pipe but it resulted in the same error and running like cmd.Run() in separate goroutine didn't help either.
Go: 1.14
OS: macOS
cmd := exec.Command("pg_restore", "--clean", "-n public", "--dbname=DB_URI")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
pw, err := cmd.StdinPipe()
defer pw.Close()
...
done := make(chan struct{})
errCh := make(chan error)
file, err := os.Open("dumpfile")
defer file.Close()
if err := cmd.Start(); err != nil {
return err
}
_, err = io.Copy(pw, file)
What am I doing wrong or how to keep pipe open?
When using cat instead of pg_restore, your code works.
When using head -10, on the other hand, I hit the same error as you, which is actually expected.
Since you are starting your cmd in async mode, if pg_restore halts before consuming all of its STDIN, io.Copy will hit this kind of error if it tries to write on a closed pipe.
Check the state of your pg_restore command (final return code, content printed on its STDERR, logs ...) to see if there is an actual error.
You can treat this error as a normal indication that you shouldn't feed input to this command anymore.
including cmd.Wait() should solve your problem, like it says int one of your comments.
With the help of my colleague we found that command arguments were malformed, since Go directly uses syscalls each argument of a program must be separate so here
-n public was leading to the issue
"pg_restore", "--clean", "-n public", "--dbname=DB_URI"
and the fix quite clear as well – split them -n, public
"pg_restore", "--clean", "-n", "public", "--dbname=DB_URI"

Unhelpful output from pytest

TLDR: How can I get better output from pytest?
I'm using Django with regular python3 unittests.
I've just switched to pytest-django for running tests.
pytest throws an error for almost all my tests (149 in total).
Pages and pages with this error.
self = <RegexURLResolver 'project.urls' (None:None) ^/>
#property
def reverse_dict(self):
language_code = get_language()
if language_code not in self._reverse_dict:
self._populate()
> return self._reverse_dict[language_code]
E KeyError: 'en-us'
Which wasn't the problem. It led me down to a wrong path.
I had a syntax error in one of my views.py files.
./manage.py test resulted in:
snip
File "/home/roland/project/views.py", line 20
code = zip(list1, list2])
SyntaxError: invalid syntax
Notice the last: ] which was the problem.
So: How can I get more useful output on problems when using pytest?
Btw:
After finding this and scrolling back into the pytest output there was mention of the syntax error. It was just buried in the output.
You can use the --maxfail=1 option so it will stop immediately on first failure.
Also, make sure your pytest.ini is setup properly so that pytest knows it should be using django-pyest.
[pytest]
DJANGO_SETTINGS_MODULE='myapp.settings'
For my workflow, I usually do the following:
run pytest --maxfail=1 myfile.py &> pytest-output.txt
tail, grep, or search he text file for errors.
Fix and iterate
There are a lot of other configuration options that will help you to get more meaningful input from pytest.

CoffeeScript --compile order in sub-directories

Is there any way to define CoffeeScript compilation order in sub-directories?
Please consider the following example:
Files:
src/App.coffee
src/view/B.coffee
src/view/a/A.coffee
Where class A extends B.
coffee --join js/app.js --compile src/view/ src/App.coffee
This throws an error in the browser:
Uncaught TypeError: Cannot read property 'prototype' of undefined
If I rename folder a to z, the error is gone and everything works fine.
src/view/z/A.coffee
I would expect the compiler to read all .coffee files from src/view/ before it goes into src/view/ sub-directories. Again, is there any way to do that?
Edit:
PC Windows 7,
CoffeeScript version 1.3.3
The only solution I think is to create the compile order manually within a build script.
You would create an ordered collection with filenames, where as the loop iterates and concatenates a new big string, which can be compiled as one file.
Create a Cakefile with following content, check Syntax first. And run with cake build. That should work, cake comes with CoffeeScript.
fs = require 'fs'
{exec} = require 'child_process'
viewsDir = "src/view"
coffeeFiles = [
'B'
'A'
]
task 'build'
# loops through coffeeFiles.
for file, index in coffeeFiles then do (file, index) ->
fs.readFile "#{viewsDir}/#{file}", 'utf8', (err, content) ->
appCoffee[index] = content
compile() if --remaining is 0
compile = ->
fs.writeFile 'js/app.coffee', appCoffee.join('\n\n'), 'utf8', (err) ->
throw err if err
exec 'coffee --compile js/app.coffee', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
# you can skip deleting the app.coffee file
fs.unlink 'js/app.coffee', (err) ->
throw err if err
console.log 'Created app.coffe, compiled to app.js and removes app.coffee'
# maybe additional taks
# invoke 'test'
Documented also in Wiki of Coffeescript https://github.com/jashkenas/coffee-script/wiki/[HowTo]-Compiling-and-Setting-Up-Build-Tools
Before first loop you could also make it loop through different directories. And just list filenames in coffeeFiles to be processed before the others not in listed and the rest could be added to list with fs.readDir().
We created a simple module to solve a similar problem:
https://github.com/Vizir/rehab
Just put #_require [filename].coffee on your file and you're done.
We are using it in productions with complex dependency graphs.